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

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);
主站蜘蛛池模板: 睢宁县| 长葛市| 新蔡县| 昭通市| 金沙县| 贵溪市| 阿拉善左旗| 合肥市| 图片| 铜鼓县| 中卫市| 渑池县| 隆德县| 修水县| 米脂县| 黄石市| 上思县| 高尔夫| 长沙市| 九龙县| 漳浦县| 扶风县| 沾化县| 合水县| 南召县| 咸阳市| 扎囊县| 嘉义市| 桦甸市| 商河县| 宣武区| 遂平县| 固始县| 沂水县| 洛阳市| 武平县| 鄂托克旗| 郓城县| 平邑县| 东明县| 金乡县|