官术网_书友最值得收藏!

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);
主站蜘蛛池模板: 剑川县| 淮阳县| 固始县| 五常市| 漠河县| 三河市| 聂拉木县| 深泽县| 威远县| 萍乡市| 昌图县| 乐东| 长垣县| 河北区| 明溪县| 汶川县| 马鞍山市| 尚义县| 崇阳县| 麻阳| 顺平县| 永安市| 桂东县| 彭阳县| 灵璧县| 石门县| 贵阳市| 离岛区| 奉贤区| 江山市| 河池市| 赫章县| 长葛市| 泽州县| 互助| 新余市| 清水河县| 于都县| 泰兴市| 怀柔区| 武乡县|