c # 9.0 empty parameter characteristic proposal to simplify the verification code

Briefly it is to null the existing characteristic parameter validation, using a simple semantic annotation further simplified.

For the following code

// Before
void Insert(string s) {
  if (s is null) {
    throw new ArgumentNullException(nameof(s));
  }
  ...
}

Simplifies to:

// After
void Insert(string s!) {
  ...
}

This proposal is executing code, the values ​​are detected.

 

Nullable type (Nullable) already present will not affect the implementation of semantic codes (code execution order).

 

But this proposal operator may change the execution order of the code, for example, does not enter the Insert function execution code.

 

c # and official documentation for new features to learn more

 

At the same time the proposal also introduces new ideas, if you can add other operators, expressions for the parameters, even linq.

 

For a function, it can be treated like an object, like processing, such as non-empty function?

 

At the same time, the proposal to increase the volume of the standard library, can make people more income?

 

Guess you like

Origin www.cnblogs.com/zero5/p/11617909.html