(b) hardware architecture matters (see (c), below).
(c) size matters ... you'll notice that the value types are simple types that for all intents and purposes have a one to one correspondence to the physical design of the CPU and, to a lessor extent, the RAM.
Get yourself a free copy of LINQPad 4* and do some experimentation ... write some very short pieces of code and look at the IL (intermediate language) by clicking IL button above the results window. Repeat your experimenents with value types ... the IL
will be different because of the way the compiler designers are able to tweak the underlying hardware.
g.
* if you do not have LINQPad 4:
TOOLS ... get yourself a FREE copy of LINQPad 4 (http://linqpad.net) .. Joe Albahari's LINQPad 4 is an awesome programmer's scratch pad that enables you to quickly check out code snippets you find in books and on web sites
plus LINQPad also lets you rapidly experiment with c# ideas before committing them to vs2010.
LINQPad 4 supports c#, F#, SQL, vb.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
P.S.: i suspect that the compiler designers could implement absolutely everything as reference types; that would not be a good idea because they would not be taking advantage of the design of the underlying hardware. OTOH, if they tried to make everything
a value type, that would lead to horrific inefficiencoes such as one might encounter when trying to force a square peg into a round hole.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
newbie2C#
Member
694 Points
1179 Posts
why are there reference types and value types?
Feb 12, 2012 01:16 PM|LINK
I understand the difference between reference and value types. I don't understand why there are the two different types though.
Can someone please explain why one type uses the value and the other uses a pointer to point to a different location in memory?
What is the advantage of having the two different types?
shashankgwl
All-Star
18926 Points
3662 Posts
Re: why are there reference types and value types?
Feb 12, 2012 01:52 PM|LINK
All is well if it runs well.
blog
Shellymn
Contributor
2600 Points
484 Posts
Re: why are there reference types and value types?
Feb 12, 2012 02:10 PM|LINK
Good article from MSDN refering the advantages and disadvantages of both value and reference types.Please go through
http://msdn.microsoft.com/en-us/magazine/cc301569.aspx
bhaskar.mule
Contributor
2270 Points
659 Posts
Re: why are there reference types and value types?
Feb 12, 2012 02:23 PM|LINK
hi
it will shown the difference between value type and reference type
http://csharpektroncmssql.blogspot.in/2011/11/diffrece-between-value-type-and.html
Site:Rare technical solutions
gerrylowry
All-Star
20513 Points
5712 Posts
Re: why are there reference types and value types?
Feb 12, 2012 03:30 PM|LINK
@ newbie2C#
this is the simplified answer.
(a) the feature is not unique to c#
(b) hardware architecture matters (see (c), below).
(c) size matters ... you'll notice that the value types are simple types that for all intents and purposes have a one to one correspondence to the physical design of the CPU and, to a lessor extent, the RAM.
http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx "Value Types (C# Reference)"
Get yourself a free copy of LINQPad 4* and do some experimentation ... write some very short pieces of code and look at the IL (intermediate language) by clicking IL button above the results window. Repeat your experimenents with value types ... the IL will be different because of the way the compiler designers are able to tweak the underlying hardware.
g.
* if you do not have LINQPad 4:
TOOLS ... get yourself a FREE copy of LINQPad 4 (http://linqpad.net) .. Joe Albahari's LINQPad 4 is an awesome programmer's scratch pad that enables you to quickly check out code snippets you find in books and on web sites plus LINQPad also lets you rapidly experiment with c# ideas before committing them to vs2010.
LINQPad 4 supports c#, F#, SQL, vb.
gerrylowry
All-Star
20513 Points
5712 Posts
Re: why are there reference types and value types?
Feb 12, 2012 03:35 PM|LINK
P.S.: i suspect that the compiler designers could implement absolutely everything as reference types; that would not be a good idea because they would not be taking advantage of the design of the underlying hardware. OTOH, if they tried to make everything a value type, that would lead to horrific inefficiencoes such as one might encounter when trying to force a square peg into a round hole.
you may find this interesting:
http://stackoverflow.com/questions/436211/is-everything-in-net-an-object