How many types of constants in .net
| There are two types of constants available in csharp. One is CompileTime and Runtime constants. Both of these are different behaviors and different performance. Most of us using Runtime constants and are peferable over compiletime constants. Althogh compiletime is faster then runtime. CompileTime are declared using const and runtime are by readonly keyword. Both of these constant can be delcared at class level.Compile time can be declared at method level a | |
| nd runtime cannot be declare at method level.
We cannot initialize using new operator in compiletime but runtime can initialized using constructor.Compiletime constants are much more better in performance but less flexible with compare to runtime constants. Runtime constants are much more flexible but its performance is slower with compare to compile-time constants. Every time application assembly need to be rebuilt whenever library assembly which contains constant gets its constant value changed.No need to rebuild Application assembly which is referring a library assembly which contains run-time constants whose value is changed and its assembly is rebuilt. | |
