Declare PI as constant in CSharp

Description

The following code shows how to declare PI as constant.

Example


public class Example2_9
{/*from www  .ja  v a2  s .co  m*/
  public static void Main()
  {

    string helloWorld = "Hello World!";
    System.Console.WriteLine(helloWorld);

    helloWorld = "Hello World" + " from C#!";
    System.Console.WriteLine(helloWorld);

    helloWorld = "Hello World" + "\n from C#!";
    System.Console.WriteLine(helloWorld);

    const double Pi = 3.14159;
    System.Console.WriteLine("Pi = " + Pi);

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var