Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

^ Operator (C# Reference)

Binary ^ operators are predefined for the integral types and bool. For integral types, ^ computes the bitwise exclusive-OR of its operands. For bool operands, ^ computes the logical exclusive-or of its operands; that is, the result is true if and only if exactly one of its operands is true.

User-defined types can overload the ^ operator (see operator). Operations on integral types are generally allowed on enumeration.

// cs_operator_bitwise_OR.cs
using System;
class MainClass 
{
    static void Main() 
    {
        Console.WriteLine(true ^ false);  // logical exclusive-or
        Console.WriteLine(false ^ false); // logical exclusive-or
        // Bitwise exclusive-or:
        Console.WriteLine("0x{0:x}", 0xf8 ^ 0x3f);
    }
}

Output

 
True
False
0xc7

Community Additions

ADD
Show:
© 2015 Microsoft