^ Operator Home
This page is specific to:.NET Framework Version:1.12.03.03.54.0
C# Programmer's Reference
^ Operator

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.

expr1 ^ expr2

Where:

expr1
An expression.
expr2
An expression.

Remarks

User-defined types can overload the ^ operator (see operator).

Example

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

Output

True
False
0xc7

See Also

C# Operators | 7.10.1 Integer logical operators

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View