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

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);
主站蜘蛛池模板: 文成县| 兴仁县| 区。| 鲁甸县| 绥中县| 连平县| 林芝县| 富蕴县| 鄂托克旗| 亳州市| 英山县| 新沂市| 丹东市| 武安市| 津南区| 江城| 司法| 威信县| 汉阴县| 古浪县| 湖南省| 建德市| 阳泉市| 香格里拉县| 商丘市| 牡丹江市| 饶阳县| 忻城县| 宿州市| 阿克陶县| 常山县| 东兰县| 宁晋县| 大田县| 新龙县| 股票| 嘉兴市| 凭祥市| 西乌| 白水县| 瓦房店市|