aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - What is the Difference between Const and Readonly

Oct 31, 2012

Here I will explain what are the differences between const and readonly in and


In previous posts I explained convert.tostring() VS .tostring(), web application VS website, difference between datareader, dataadapter and dataset, difference between tinyint, smallint, int, bigint and many articles relating to, SQL Server. Now I will explain the difference between const and readonly in and


      1.    Const can only be initialized at the time of declaration of the field.
      2.    Const values will evaluate at compile time only.
      3.    Const value can’t be changed these will be same at all the time.
      4.    This type of fields are required when one of the field values remains constant throughout the system like Pi will remain same in your Maths Class.


     1.    The value will be initialized either declaration time or the constructor of the class allowing you to pass the value at run time.
      2.    Read only values will evaluate at runtime only.

public class Const_VS_Readonly
public const int I_CONST_VALUE = 2;
public readonly int I_RO_VALUE;
public Const_VS_Readonly()
Suppose if you want the value of the constant won't change use a const or if you have a constant that may change or when in doubt, use a readonly.  I hope it helps.

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


vipin pandey said...

hi suresh ji! you r doing great job.thanks for you articles.

sir,its my request to u ,please teach us MVC and WCF.
highly thankful to you. one of the most valuable sites for .net

Harsha said...

i always get confused with these two keywords, i faced this question many times in interviews. thank you for sharing.

Harsha said...

one more difference is, readonly variables can only be declared as global variables, but const variables can also be declared in a method or constructor.

Anonymous said...

nice sir...but i have a small confusion that is what is the difference b/w static and const and read only?

Anonymous said...

thanks sir,
can you please explain static is well

Anonymous said...

thanks sir,it is really a nice site for .net

Vipin Kushwaha said...


Vipin Kushwaha said...


sureshdangeti said...

hi suresh, u done great job, i am unable to post or
send feedback,

Krishan Kumar said...

thank sir
Please MVC and WCF article need, help me

Anonymous said...

really a nice site for .net learners.....

Anonymous said...

this site is really nice.. easy to understand

Anonymous said...

Knowledge distribution is a great thing nice one...

Anonymous said...

you doing great job sir,your articles helps lot for .net people

Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.