Charlie - 10 months ago 86

C# Question

For example, does an operator exist to handle this?

`float Result, Number1, Number2;`

Number1 = 2;

Number2 = 2;

Result = Number1 (operator) Number2;

In the past the

`^`

Do I have to write a loop or include another namespace to handle exponential operations? If so, how do I handle exponential operations using non-integers?

Answer

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);
```

Source (Stackoverflow)