?? Operator (C # reference ),

Source: Internet
Author: User

?? Operator (C # reference ),

?? An operator is a null merge operator that defines the types that can be null values and the default values of reference types. If the left operand of this operator is not null, this operator returns the left operand; otherwise, the right operand is returned.

class NullCoalesce{    static int? GetNullableInt()    {        return null;    }    static string GetStringValue()    {        return null;    }    static void Main()    {        // ?? operator example.        int? x = null;        // y = x, unless x is null, in which case y = -1.        int y = x ?? -1;        // Assign i to return value of method, unless        // return value is null, in which case assign        // default value of int to i.        int i = GetNullableInt() ?? default(int);        string s = GetStringValue();        // ?? also works with reference types.         // Display contents of s, unless s is null,         // in which case display "Unspecified".        Console.WriteLine(s ?? "Unspecified");    }}

Bitwise XOR operators in C Language

1: The "bitwise AND" Operator (&) is used if both of the corresponding binary bits are 1, The result value of this bits is 1 or 0. 0 & 0 = 0, 1 & 0 = 0, 1 & 1 = 1
2: The bitwise OR operator (|) is used if one of the two binary bits is 1, The result value of this bits is 1 or 0. 0 & 0 = 0, 1 & 0 = 0, 1 & 1 = 1
0, 1 & 0 = 1, 1 & 1 = 1
3: The "XOR" Operator (^) is used if two corresponding binary bits are of the same number, the result value of this bits is 1 or 0. 0 & 0 = 1, 1 & 0 = 0, 1 & 1 = 1

What is the condition operator in C?

Conditional operators (? :) It is the only three-object operator in C language, that is, it has three operation objects. The condition operator is in the form "? : "The expressions composed of them are called conditional expressions.
The conditional expression is in the following format:
Expression 1? Expression 2: expression 3
Example: (a> B )? A + B: a-B
Where, if a = 2, B = 1, then a> B is true, execute the expression a + B, and the calculation result is 3; but if a = 2, B = 3, if expression a> B is not true, execute the expression a-B and the result is-1.

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.