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 redim keyword and its use?

586


Thank you for replying to my Question regarding Barcodes in VB.net. My next question is that how to use Barcode Fonts in VB.net I need a small code to Generate Barcodes in VB.net from a string of Values. This is the only problem i am left with in my project. Any body can help me please.

2037


Why do you need Lock in Visual Basic?

609


What is the role of new keyword?

622


What is branching logic control in VB.NET?

568






Is vb.net dead?

522


Why should you use delegate?

472


Name a feature which is common to all .net languages?

576


How many languages are supported by .net?

547


described weak typing?

585


What is redim keyword?

573


Tell us how many languages are supported by .net?

507


Explain about the ruby interface generator?

548


Explain the advantages of vb.net?

525


what is difference between namespace and assembly?

530