what is read only and constant

Answer Posted / xiaof

A const field can only be initialized at the declaration of
the field. A readonly field can be initialized either at
the declaration or in a constructor. Therefore, readonly
fields can have different values depending on the
constructor used. Also, while a const field is a compile-
time constant, the readonly field can be used for runtime
constants as in the following example:
public static readonly uint l1 = (uint) DateTime.Now.Ticks;

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you inherit from a sealed class?

498


Can you drink alcohol with a loop recorder?

498


What is a multicast delegate in c#?

539


Why singleton class is sealed?

485


What is parallel foreach c#?

514






Any problem found in vs.et

590


Is c# and c sharp same?

490


What is array collection?

496


Explain polymorphism in c# with a simple example?

517


Is post back in c#?

525


Explain the difference between user control and custom control. Also, explain their use.

598


Why do we use public static void main in c#?

473


What is difference between function and method in c#?

465


Why are c# strings immutable?

509


Give examples for reference types?

541