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

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);
主站蜘蛛池模板: 梅州市| 自治县| 揭西县| 海兴县| 太谷县| 绥中县| 眉山市| 天镇县| 象山县| 临高县| 肃南| 阿克陶县| 昌邑市| 揭阳市| 宁强县| 九寨沟县| 乃东县| 双辽市| 霍城县| 兖州市| 阳西县| 宁乡县| 华亭县| 西林县| 汝城县| 安塞县| 沈阳市| 孝感市| 华容县| 瑞昌市| 合水县| 林西县| 泰宁县| 碌曲县| 夹江县| 关岭| 清丰县| 井冈山市| 通城县| 晋中市| 梁山县|