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


Please Help Members By Posting Answers For Below Questions

What is the difference between manifest and metadata?

723


Allowed program to auto-correct the database when loading a presentation.

1932


Explain trace in vb.net?

716


Explain the use of console application?

709


What do you mean by serialization and deserialization and it's use.

815


Explain about the ruby interface generator?

731


How a base class method is hidden?

797


What are the various open source tool available for VB.NET?

735


Is vb net a scripting language?

721


Define clr?

719


What is trace in vb.net?

769


Explain the use of serialization and deserialization?

734


What languages does the .net framework support?

724


Explain jagged array in vb.net?

732


What is the ruby interface generator?

754