In C #?? Operator and? Operator

Source: Internet
Author: User

In C #?? And? How the operator is used and what it means:

For the conversion of nullable data to non-nullable type data

?? The operator means to take the copy?? To the left, if the left is null, take the assignment?? On the right.

? is System. Abbreviated form of nullable, int? Represents a nullable integral type

       例如:int? a = 1 或者 int? b=null。Nullable类型具有一个HasValue的bool类型只读属性,当Nullable类型实例的该属性为true时,则表示该实例是非空实例,包含一个已知值Value,

HasValue为 false 时,访问Value属性将导致System.InvalidOperationException。such as int I = NULL So the compilation will go wrong, but if it is an int? I =null can be executed in normal

In C #?? Operator and? Operator

Related Article

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.