Is there an exponent operator in C#?

后端 未结 8 1605
萌比男神i
萌比男神i 2020-11-28 08:09

For example, does an operator exist to handle this?

float Result, Number1, Number2;

Number1 = 2;
Number2 = 2;

Result = Number1 (operator) Number2;
<         


        
8条回答
  •  醉酒成梦
    2020-11-28 08:50

    The C# language doesn't have a power operator. However, the .NET Framework offers the Math.Pow method:

    Returns a specified number raised to the specified power.

    So your example would look like this:

    float Result, Number1, Number2;
    
    Number1 = 2;
    Number2 = 2;
    
    Result = Math.Pow(Number1, Number2);
    

提交回复
热议问题