Constants C#, Brief Explanation

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…

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;

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *