views:

1443

answers:

1

I read that the ^ operator is the logical xor operator in c#, but i also thought it was the "power of" operator. Can someone clear this up for me?

+16  A: 

It is not the power of operator of C# since there is no such operator in C#. It is just the XOR operator.

For "power of", use Math.Pow.

As you can see from this page on the C# Operators, ^ is listed under the "Logical (boolean and bitwise)" category, which means it can both handle boolean values, and binary values (for bitwise XOR).

Lasse V. Karlsen
hmm, then wherever i was using that operator as "power of" i'll have to fix at some point...
RCIX
Just to add: The PowerOf Function in C# is Math.Pow. http://msdn.microsoft.com/en-us/library/system.math.pow.aspx
Michael Stum
@RCIX: Didn't you notice any incorrect results when you were attempting to use `^` as the power-of operator?
LukeH
`^` is the "power of" operator in VB.NET.
Christian Hayter