- Compile-Time constants are defined using the keyword "const"
- Run-Time constants are defined using the keyword "readonly"
Compile-Time constants are relatively faster than run-time constants but are less flexible. Generally speaking run-time constants are better than compile constants despite the fact that they might be slightly slower.
//Compile-Time constant
public const int Pi=3.14;
//Run-Time constant
public static readonly float Pi=3.14;
Compile-Time constants are resolved at compile time, and their value will be placed directly in the code, even across the assemblies.
No comments:
Post a Comment