What are Constants - CSharp Custom Type

CSharp examples for Custom Type:Constant

Introduction

A constant is a static field whose value can never change.

A constant can be any of the built-in numeric types, bool, char, string, or an enum type.

A constant is declared with the const keyword and must be initialized with a value.

For example:

public class Test
{
 public const string Message = "Hello World";
}

Constants can also be declared local to a method. For example:

static void Main()
{
 const double twoPI  = 2 * System.Math.PI;

}

Non-local constants allow the following modifiers:

Access modifierspublic internal private protected
Inheritance modifier new

Related Tutorials