- ASP.NET Core 2 High Performance(Second Edition)
- James Singleton
- 100字
- 2021-07-08 09:38:58
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);
推薦閱讀
- Learning Single:page Web Application Development
- Python編程自學手冊
- Spring Boot開發與測試實戰
- Visual FoxPro程序設計教程(第3版)
- Web交互界面設計與制作(微課版)
- Java編程指南:基礎知識、類庫應用及案例設計
- Spring Cloud、Nginx高并發核心編程
- Java加密與解密的藝術
- iOS編程基礎:Swift、Xcode和Cocoa入門指南
- Oracle 18c 必須掌握的新特性:管理與實戰
- App Inventor 2 Essentials
- C++從入門到精通(第6版)
- Web前端測試與集成:Jasmine/Selenium/Protractor/Jenkins的最佳實踐
- Python網絡爬蟲從入門到實踐
- Visual Basic 開發從入門到精通