What is the difference b/w Readonly Variable and Constant
Variable?
Answer Posted / arun
constants are dealt with at compile-time, while static
readonly fields are set at the time they are evaluated at
run-time.
the constant value will need to be recompiled if the
constant value changes. Libraries referencing a static
readonly field will reference the field and not the value,
thus they will pick up any change in the field without the
need for recompilation
constants will only support value types plus the
special .NET ones string and null while Static readonly
fields are able to hold reference types too.
So, constants should be used when it is very unlikely that
the value will ever change, or if no external apps/libs
will be using the constant. Static readonly fields should
be used when run-time calculation is required, or if
external consumers are a factor
| Is This Answer Correct ? | 10 Yes | 2 No |
Post New Answer View All Answers
Name a feature which is common to all .net languages?
Explain convert.tostring and i.tostring method?
Explain jagged array in vb.net?
Explain the difference between value and reference types?
Name the tool which can convert visual basic old version to .net compatibility version?
Which class allows an element to be accessed using unique key?
What is the difference between static or dynamic assemblies?
Explain the differences between vb.net and c#, related to oops concepts?
Can you please explain the difference between dataset and datareader?
What is datatype conversion?
Can you please explain the difference between c# and vb.net?
How a base class method is hidden?
What is a static class?
Explain the use of option explicit?
Which dll is used for microsoft .net run time?