C # 7.2 new features

C # 7.2 is a single-point version, which adds a number of useful features. A key feature of this version is to avoid unnecessary duplication or distribution, resulting in more efficient handling type value.

Use C # 7.2 language versions of selected configuration element to select the language compiler version.

01 security enhancements and efficient code

Using the language functions introduced 7.2, when value types can be processed reference semantics. They are intended to minimize the value of the type of replication, without causing memory allocation and use of related reference types, and thus enhance performance. Features include:

  • For argument  in modifiers, designated parameter passed by reference, but not modified by calling the method. Will be  in adding a modifier to the parameter is compatible with the source changes .
  • Method for the return of  ref readonly modifier, the method returns a value indicating by reference, but not written to the object. If a value is given to the return value, then add the  ref readonly modifier is compatible with the source changesWill  readonly add a modifier to an existing  ref return statement is incompatible changeIt requires the caller to update  ref declare a local variable to contain  readonly modifiers.
  • readonly struct Statement, indicating structure immutable, and should be used as  in parameters are passed to its member methods. Will  readonly add a modifier to an existing structure declaration is binary compatible change .
  • ref struct A statement indicating the type of structure direct access to managed memory, and must always be assigned the stack. Will  ref add a modifier to an existing  struct declaration is incompatible changeref struct You can not be a member of the class, nor for possible other locations allocated on the heap.

You can write secure efficient code to learn more about all of these changes.

02 non-trailing named parameters

Method calls now named parameters in front of the position parameter (if these named parameters to correct position). For more information, please refer to named and optional parameters .

03 leading underscore the value of the text

C # 7.0 implements support for digital delimiters, but does not allow the first character literal value is  _Hexadecimal text and binary files can now  _ begin with. E.g: 

int binaryValue = 0b_0101_0101;
04 private protected access modifier

The new complex access modifier: private protected instructions can be accessed by members of the class or derived class contains the same assembly declared. While  protected internal allowing the centralized procedure by the same class or derived class to access, but  private protected restrict access to the derived class declaration focused on the same program.

For more information, see the language reference access modifier .

05 ref expression condition
Ref conditional expressions may produce results rather than value. For example, you would write the following to retrieve one of the two arrays, the first element of reference:
ref var r = ref (arr != null ? ref arr[0] : ref otherArr[0]);

Variable  r is  arr or  otherArr the first reference value.

For more information, see the Language Reference conditional operator (? :) .

Guess you like

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