Each version of the new C # C # 7.2 features

Efficient and safe code enhancements

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

  • For the argument in the modifier, designated parameter passed by reference, but not modified by calling the method. Adding to be compatible with the source parameter change in modifier.
  • Method for ref readonly modifier returned, indicating the method returns its value 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 changes. Adding to the existing readonly modifier ref return statement is incompatible change. It requires the caller to update ref declared local variable to contain the readonly modifier.
  • readonly struct statement indicating structure immutable, and should be passed in as a parameter its member methods. The readonly modifier added to the existing structure declaration is binary compatible changes.
  • ref struct declaration, indicating the type of structure direct access to managed memory, and must always be assigned the stack. Add the ref modifier to an existing struct declaration is incompatible change. ref struct can not be a member of the class, nor for possible other locations allocated on the heap. Writing efficient security code

Non-trailing named parameters

You can use normal, do not look;

Leading underscore the value of digital

int binaryValue = 0b_0101_0101;

private protected access modifier

private protected: restricting access to the class or type of the current assembly comprising a self-contained class derived

// Assembly1.cs 
// Compile with: /target:library 
public class BaseClass
{
    private protected int myValue = 0;
}


public class DerivedClass1 : BaseClass
{
    void Access() //正确方法
    {
        myValue = 5; //可以正常访问
    }

void Method1()
{
        var baseObject = new BaseClass();
        // baseObject.myValue = 5;  // because myValue can only be accessed by    classes derived from BaseClass.
    }
}

protected internal: restricting access to the current type self-contained assembly or derived classes

Conditions expression ref

ref var r = ref (arr != null ? ref arr[ 0 ] : ref otherArr[ 0 ]);

Guess you like

Origin www.cnblogs.com/maanshancss/p/7be07e2502df85536ab84a9490162a06.html
Recommended