C # 7.1 new features

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:

  1. Install  dotnet-try  a global tool.
  2. Cloning  dotnet / try-samples  repository.
  3. Csharp7 the current directory to a subdirectory try-samples repository.
  4. Run  dotnet try.
01 asynchronous main method
Asynchronous Main  method so that you can  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.

02 default text expression
The default text expression is an enhancement for the default value of the expression. These expressions variable is initialized to the default value. In the past it would be so written:
Func<string, bool> whereClause = default(Func<string, bool>);
Now, the initialization may be omitted on the right side of type:
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.

03 inference tuple element name
This feature is a small enhancement to the tuple function introduced in C # 7.0. At initialization tuple, in many cases, assign variable names to the right of operation is the same name used for tuple elements:
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.

Mode 04 generic type parameter matches
Since C # 7.1 onwards, 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.
05 references generated assemblies
There are two new compiler option to generate only refer to the assembly: -refout  and  -refonly  . Linked article details these options and reference the assembly.
 

Guess you like

Origin www.cnblogs.com/SavionZhang/p/11199958.html