A constant is evaluated statically at compile time, and the compiler literally substitutes its value whenever used.
A constant can serve similar role to a static readonly field, but it is more restrictive. A constant also differ from a static readonly field in that the evaluation of the constant occurs at compile time.
Constant:
public static double Circumference (double radius) {
return 2 * System.Math.PI * radius;
}
static readonly:
static readonly DateTime StartupTIme = DateTime.Now;
Leave a Reply