C #"?? "And "? "Operator

Source: Internet
Author: User
The condition operator is associated to the right and is calculated from left to right, so? B: C? D: E should be understood as? B :( C? D: E ). The nullable data type is implemented in C #2.0, Abandon pair object Data if object == null . At the same time, you will find that, In database applications, some fields in the Database allow null values, and the introduction of the nullable type in the C # world exactly corresponds , Ing from (C #) objects to relational database objects, or vice versa, the conversion is relatively smooth.   In order to convert the nullable data type into non-nullable data, there is such an operator "?? (Two question marks) ", the double question mark Operator means to take the assigned value ?? Left, if the left is null , Take the assigned value ?? On the right, For example int Y = x ?? -1 if X is null, the value of Y is-1. At this time, you can change the second code at the top: string strParam= Request.Params[ "param" ]?? "" ; Hey, is it more concise. There are also "? (Single question mark) "modifier, abbreviated form of system. nullable, such int ? Represents an empty integer, For example: int ? A = 1 or int ? b= null . The nullable type has a hasvalue bool Type Read-only property, This attribute is true It indicates that the instance is a non-empty instance and contains a known value, Hasvalue is false When the value attribute is accessed, system. invalidoperationexception occurs.Reprinted: http://www.cnblogs.com/refactor/archive/2012/05/30/2526147.html

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.