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

Is it necessary to have SQL server installed in your computer in order to create a service based database in vb.net?

1872


Why do you need Lock in Visual Basic?

620


What keyword is used to accept a variable number of parameter in a method?

585


Explain the difference between vb 6 and vb.net?

547


What is the purpose of an Assembly?

616






Is vb net a scripting language?

559


what is common language specification?

525


What are option strict and option explicit?

802


Explain the difference between import system.data.sqlclient and system.data.oledb?

561


What is a literal control?

587


What is an application domain? how they get created?

591


What is meant by jagged arrays?

588


my project run very wel in my sytem yhen i am deploying my project on client machine ,after deployment i run my project then it show " can no find server name " what i do .

1565


Can you please explain the difference between c# and vb.net?

549


Which classes a dll can contain?

544