The C # 6.0 release contains many features that can improve developer productivity. features in this release include the following:
- Read-only automatic properties:
- You can create a read-only automatic property that can be set only in the constructor.
- Automatic Property initializers:
- You can write an initialization expression to set the initial value of an automatic property.
- expression-bodied function Members:
- You can use a lambda expression to create a single-line method.
- Using static:
- You can import all methods of a single class into the current namespace.
- Null-Conditional operator:
- You can access the members of an object concisely and securely, while still checking for NULL using the null condition operator.
- String interpolation:
- You can use inline expressions instead of positional arguments to write string formatting expressions.
- Exception Filters:
- You can capture an expression based on a property of an exception or other program state.
- Nameof expression:
- You can have the compiler generate a string representation of the symbol.
- Await in Catch and Finally block:
- You can use them where you have not previously allowed
await
expressions to be used.
- Index initializers:
- You can create an initialization expression for an associative container and a sequence container.
- Extension methods for collection initializers:
- In addition to the member method, a collection initializer can also rely on an accessible extension method.
- Improved overload resolution:
- Some constructs that have previously generated ambiguous method calls can now be parsed correctly.
The overall effect of these features is to make the code you write more concise and more readable. This syntax is not as cumbersome as many common practices. design Intent can be seen more easily. having a good understanding of these features can help you work more efficiently, write more readable code, and focus more on core functionality than language constructs.
Original: Https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-6
c#6.0 new Features