Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math Pow() method is used to return the base raise to the Power of exponent. In special cases it returns the following:

  • If any of the arguments is NaN, the method returns NaN.
  • If the base is -1 and exponent is either PositiveInfinity or NegativeInfinity, the method returns NaN.
  • If the base is less than zero but not NegativeInfinity and exponent is not Integer, PositiveInfinity or NegativeInfinity, the method returns NaN.
  • If the base is NegativeInfinity and exponent is positive but not odd integer, the method returns PositiveInfinity.
  • If the absolute value of base is less than 1 and exponent is NegativeInfinity, the method returns PositiveInfinity.
  • If the absolute value of base is greater than 1 and exponent is PositiveInfinity, the method returns PositiveInfinity.

Syntax

public static double Pow (double base, double exponent);

Parameters

base Specify the base.
exponent Specify the exponent.

Return Value

Returns the base raise to the Power of exponent.

Example:

In the below example, Pow() method is used to calculate the base raised to the Power of exponent.

using System;

class MyProgram {
  static void Main(string[] args) {
	Console.WriteLine(Math.Pow(2, 3)); 
	Console.WriteLine(Math.Pow(2.3, 4));   
  }
}

The output of the above code will be:

8
27.98409999999999

❮ C# Math Methods