C # tips-null type

Source: Internet
Author: User

 

1) In 1 If one of the operands is Null Or both Null , The result is Null .
For example:
Int? A = NULL;
Int? B = a + 3;
ThenBIsNull

 

2)When the comparison can be empty, as long as one operand isNullAnd the result isFalse

For example:

Int? A = NULL;

Int? B = 8;

(A> = B)ReturnsFalse

BecauseNullTherefore, you cannot compare an empty type with a non-empty type.

 

3)Null join Operator

Null join Operator "??" This parameter is used to process null and reference types. Null The possibility of a value provides a shortcut, maybe we don't need to always write If (XX! = NULL) . A bit similar to a ternary Operator "? :" , If "??" The previous number (the first number must be null or the reference type) is not Null, The expression value is the value of the first operand. If the first operand is Null The value of the expression is the value of the second expression.

For example:

Int? A = NULL;

Int defaut = 1010;

Int B;

B = ?? Defaut ;//In this caseBFetchDefautValue

A = 8;

B = ?? Defaut; // B A value

Of course, here the second number should be the same as the first number type or be implicitly converted to the first number.

 

PS:An empty type based on the reference type cannot be created because the reference type is supported.Null Value.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.