VJs Tip Of the Day
Reply
![]() |
|
From:
![]() VishalRJoshi
|
Const vs. readonly in C#
const (Constants) are variables whose values are set at compile time, either by the programmer or by the compiler... It cannot be modified there after, so if you need a field whose value is known at compile time and should not be changed anytime later then you should declare that field as const... Interesting note is that const fields are static by default and so you do not need to instantiate a class to access them...
readonly (Read Only) are variables whose values are set at run time, but only once... The value of such variables are set in the constructors and cannot be modified there on... These variables are useful when you want the value of the variable to be fixed but fixed to a value which is known only at run time... See this is what C# offers... :-)
Now if you need a static variable whose value is known only at runtime then make it static readonly... :-)
Vishal Joshi Microsoft MVP .Net If You Think YOU CAN... You Can... http://VishalJoshi.Blogspot.com http://www.microsoft.com/india/mvp/indiamvp.aspx http://groups.msn.com/ChennaiNetUserGroup http://groups.msn.com/CNUG-DAM http://groups.msn.com/NetBloomingtonUserGroup
|
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|