How can you say that integer is Value type

Posted by Parimi.chowdary under Interview Questions on 10/18/2011 | Points: 10 | Views : 955 | Status : [Member] | Replies : 2
How can you say that integer is Value type.What is base that integer is value type and string is refrence type.




Responses

Posted by: Hmanjarawala on: 10/18/2011 [Member] Bronze | Points: 25

Up
0
Down
Integer is derived from System.ValueType where string is not.
more over that Strings aren't value types since they can be huge, and need to be stored on the heap. Value types are (in all implementations of the CLR as of yet) stored on the stack. Stack allocating strings would break all sorts of things: the stack is only 1MB, you'd have to box each string, incurring a copy penalty, you couldn't intern strings, and memory usage would balloon

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Parimi.chowdary, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 10/18/2011 [Member] Starter | Points: 25

Up
0
Down
basically int,double are struct and structure in c# are value type therefore int is a value type whereas string is class and class is a reference type so string type are reference type.

Kind Regards,
Jay

Parimi.chowdary, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response