C # 7.1 version is the first point of the C # language (updated version). It marked the release accelerated rhythm of language. Ideally, you can more quickly introduce new features in each new feature is ready. C # 7.1 adds the compiler configuration to match specific language version of the function. So you can make decisions about the upgrade version of the language and decision-making related to the upgrade tool, respectively.
C # 7.1 adds language version selected configuration elements, three new language features and new compiler behavior.
Finally, there are the compiler -refout
and -refonly
two options can be used to control the reference assemblies generated .
To use the latest version features a single point, you need to configure the compiler language version and the version selected.
The rest of this article provides an overview of each function. You will understand the principles behind each function. You will learn grammar. You can use dotnet try
a global tool navigate through the functions in the environment:
- Install dotnet-try a global tool.
- Cloning dotnet / try-samples repository.
- Csharp7 the current directory to a subdirectory try-samples repository.
- Run
dotnet try
.
Main
use the await
keyword. In the past, we need to write:
static int Main() { return DoAsyncWork().GetAwaiter().GetResult(); }
Now, you can write:
static the async the Task < int > the Main () {
// DoAsyncWork, including waiting expression: return the await DoAsyncWork (); }
If the program does not return an exit code, you can declare the return Task of Main
methods:
static async Task Main() { await SomeAsyncMethod(); }
For more details, read the Programming Guide asynchronous Main article.
Func<string, bool> whereClause = default(Func<string, bool>);
Func<string, bool> whereClause = default;
To understand this enhancement in detail, you can see C # Programming Guide default value expressions article.
This enhancement will also change some of the default keyword analysis rules.
int count = 5; string label = "Colors used in the map"; var pair = (count: count, label: label);
Name tuple element can be inferred by the variable C # 7.1 initialized tuple used:
int count = 5; string label = "Colors used in the map"; var pair = (count, label); // element names are "count" and "label"
To learn more about this feature, you can see the tuple article.
is
and switch
type type mode of expression patterns may be a generic type parameter. This may inspect struct
or class
most useful and want to avoid the type of packing.