Wednesday, February 11, 2009

Operator ^ in C#

Yesterday I was surprised with Question:



In VB.NET we can use caret for computing the power of some number. Example:
double power=2^3
power will have the value of 8.



How can we do that in C#?






Yes, C# is has the caret (“^”) operator, but that operator does XOR , so what to do?






Answer is relative simple:
Use the System namespace and Math class which have Method Pow
double power=System.Math.Pow(2,3)