This is just a thought, that I was thinking why can't we have a constant with static in C#, and the answer is 'NO';
That we cannot have a static constant; e.g:
I created a class as below:
public class Constants1
{
public const string Const1 = "Hello";
public const string Const2 = "World";
public static string Static1 = "Hello Static";
}
When we compile the program into IL, the C# compiler does a magic in IL, that the constants converts into static literals, of course it has to, that's why we are able to access the constants as Constants1.Const1

Comments
Post a Comment