- ASP.NET Core 2 High Performance(Second Edition)
- James Singleton
- 100字
- 2021-07-08 09:38:58
Expression bodies
Expression bodies allow you to assign an expression to a method or getter property using the lambda arrow operator (=>), which you may be familiar with from fluent LINQ syntax. You no longer need to provide a full statement or method signature and body. This feature has also been improved in C# 7, so see the examples in the next section.
For example, a getter property can be implemented like so:
public static string Text => $"Today: {DateTime.Now:o}";
A method can be written in a similar way, such as the following example:
private byte[] GetBytes(string text) => Encoding.UTF8.GetBytes(text);
推薦閱讀
- Learning NServiceBus(Second Edition)
- Spring技術內幕:深入解析Spring架構與設計
- Mastering Kotlin
- C語言最佳實踐
- 老“碼”識途
- Flux Architecture
- 小學生C++創意編程(視頻教學版)
- Learning Continuous Integration with TeamCity
- 人工智能算法(卷1):基礎算法
- Instant GLEW
- Mastering ArcGIS Server Development with JavaScript
- 產品架構評估原理與方法
- JBoss AS 7 Development
- Java Web入門很輕松(微課超值版)
- Natural Language Processing with Java Cookbook