0

Since the constants in c# are also static, then why we are able to declare them as local variable in a method?

public void abc()
 {
    const int a = 10;
 }
  • So you can use them inside your methods but never change them? – Ian H. Sep 08 '16 at 05:44
  • A constant is not a variable, and not actually stored anywhere. As it isn't stored, it's not an instance member, and it's not static. Constants are classified as static members(for some reason), but they are not stored statically The constant is just a name for a value. When the code is compiled the value is inserted where the constant is used. Changing the declared value of the constant doesn't change the value used until you recompile the code that uses the constant. So, a constant declared locally works exactly as a constant declared anywhere else, it's only the scope that differs. – Mohammad Sherif Sep 08 '16 at 05:44

0 Answers0