- 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 Microsoft Windows Server 2012 Dynamic Access Control
- Web交互界面設計與制作(微課版)
- FreeSWITCH 1.6 Cookbook
- 數據結構(Python語言描述)(第2版)
- AutoCAD VBA參數化繪圖程序開發與實戰編碼
- Learning OpenStack Networking(Neutron)
- Oracle 18c 必須掌握的新特性:管理與實戰
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- Fastdata Processing with Spark
- Java并發編程:核心方法與框架
- Learning Unreal Engine Game Development
- Java高手是怎樣煉成的:原理、方法與實踐
- Instant Pygame for Python Game Development How-to
- Clojure編程樂趣
- Performance Testing with JMeter 3(Third Edition)