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

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);
主站蜘蛛池模板: 屏东市| 平江县| 永寿县| 昭觉县| 平阳县| 郓城县| 大同县| 宁阳县| 墨竹工卡县| 道孚县| 定结县| 上虞市| 大埔县| 冀州市| 云和县| 锦屏县| 泽库县| 明溪县| 丹巴县| 玉林市| 沭阳县| 明光市| 自治县| 通州区| 清苑县| 新绛县| 萨嘎县| 新田县| 通渭县| 苗栗县| 沁水县| 太原市| 拜城县| 泽库县| 天门市| 古浪县| 合山市| 河北省| 丘北县| 小金县| 恭城|