.NET FAQs Unleashed!
 
    
    

What is the difference between const and readonly in C#?

When using the const keyword to set a constant variable, the value needs to be set at compile time. The const keyword may not be used with an object of reference type.

In case a reference type needs to be assigned a non-changeable value, it may be set as readonly

Protected Internal  Array  Sort Array  Throw  Multiple Catch  Polymorphism  Inheritance  Session Viewstate  Autogenerate  ReadOnly  Sealed Class  Sealed Method  Multiple Interfaces  Overloading  Overloaded Constructors  Generics  Main  Case Sensitive  Console  Specifier  Return Type  SetCommandLineArgs  System Environment  New  Default Values of Types Compiler Error Constant Variable Const Const - ReadOnly Parameter Modifier Out Ref Interface Interface Reference, is, as System.Collection

More Interview Questions...