Xpode.com        Click here to Print this article.

What is the difference between CONST and READONLY

Both are meant for constant values. 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.

				
readonly int b;
public X()
{
b=1;
}
public X(string s)
{
b=5;
}
public X(string s, int i)
{
b=i;
}

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; 

(this can not be possible with const)






Contributed by:
Guest
Guest user is that user who have done some activity on website without login. Activity contains commenting on any article, uploading an image on website etc.

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=222

Click here to go on website