This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16216|Reply: 1

[Tips] C# question mark? operator

[Copy link]
Posted on 8/14/2018 10:15:20 AM | | |
1. Conditional operator ?:
For example: a == null ? null : a.x;
This is the most common question mark? operator.
Support: All versions C #

2. Shorthand int for null type definition?
Null values in C# cannot be assigned to value types, if the value type needs to be set to empty, it must be defined with: System.Nullable<T> t, abbreviated as T? t
For example, System.Nullable<int> total can be abbreviated as: int? total
Support: >= .NET Framework 4.0

3. Null Merge Operator ??
If the left operand of this operator is not null, this operator returns the left operand; Otherwise, the right operand is returned.
For example:
    int x?;  
    int y = x ?? -1;
Support: >= .NET Framework 4.0

4.null conditional operator ?.
Used to test for the presence of NULL before performing a member access (?.) or index (?[) operation.
if(a != null)  a.x();   Equivalent to a?. x();
Support >= C# 6.0





Previous:Mchain is a crazy MLM coin
Next:mybatis prevents SQL injection
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com