Const
The constant member is determined at compile time and cannot be changed at run time. Constants are declared as a field using the const keyword and must be initialized as they are declared. For instance:
public class MyClass
{
public const double PI = 3.14159;
}
cannot declare a class member as "static const".
- Because member variables declared as "const" are already "static".
PI cannot be modified in the application anywhere else in the code, as this will cause a compiler error.
only for reading
, . , readonly , .
:
public class MyClass
{
public readonly double PI;
public MyClass()
{
PI = 3.14159;
}
}