explain difference between constant & read only in C#

Posted by Sekar.C under Interview Questions on 4/23/2012 | Points: 10 | Views : 3693 | Status : [Member] | Replies : 8
Hi,
explain difference between constant & read only in C# own words
Regards
sekar.c

Regards
Sekar.c



Responses

Posted by: Dotnetrajanikanth on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
http://stackoverflow.com/questions/55984/what-is-the-difference-between-const-and-readonly

____________
www.flickr.com/photos/psdesigner/

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santhiram on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
Readonly fields can be initialized at compile time & runtime also where as const members can be initialized only at compile time.

Thanks
Shanti

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/23/2012 [Member] Silver | Points: 25

Up
0
Down
Constant variable once assigned can't be changed, but ReadOnly variable can be changed on the fly.


Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/23/2012 [Member] Silver | Points: 25

Up
0
Down
Refer this link..

http://abdullin.com/journal/2008/10/22/const-vs-readonly-vs-static-readonly-in-c-net.html

Regards,
Singaravel M

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savariya on: 4/24/2012 [Member] Starter | Points: 25

Up
0
Down
Main Difference between Constant and readonly is that
At the time of declaration you MUST have to define some value for constant variable where as for readonly variable you can definne its value Later(Only in constructor) also


ThANKS

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandeepmhatre on: 3/23/2013 [Member] Starter | Points: 25

Up
0
Down
Refer this link

http://sandeepmhatre.blogspot.com/2013/03/constants-and-read-only.html

Sandeep M,
Software Developer
Follow me on :
http://sandeepmhatre.blogspot.in

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/23/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

refer this
http://www.aspdotnet-suresh.com/2012/10/cnet-what-is-difference-between-const.html

Mark as Answer if its helpful to you

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: VINI1985 on: 3/28/2013 [Member] Starter | Points: 25

Up
0
Down
Whenever declare Constant variable it is mandatory to initialize as well
one more thing with constant can not be static.

Whenever declare readonly variable it is not mandatory to initialize as well
one more thing with constant can be static.

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response