why are there reference types and value types?http://forums.asp.net/t/1768667.aspx/1?why+are+there+reference+types+and+value+types+Sun, 12 Feb 2012 15:35:26 -050017686674828373http://forums.asp.net/p/1768667/4828373.aspx/1?why+are+there+reference+types+and+value+types+why are there reference types and value types? <p>I understand the difference between reference and value types. &nbsp;I don't understand why there are the two different types though.</p> <p>Can someone please explain why one type uses the value and the other uses a pointer to point to a different location in memory? &nbsp;&nbsp;</p> <p>What is the advantage of having the two different types?</p> 2012-02-12T13:16:13-05:004828401http://forums.asp.net/p/1768667/4828401.aspx/1?Re+why+are+there+reference+types+and+value+types+Re: why are there reference types and value types? Because traditionally program data has been stored on stack whereas heap is a portion of RAM hence two types of storage requires two data type 2012-02-12T13:52:13-05:004828415http://forums.asp.net/p/1768667/4828415.aspx/1?Re+why+are+there+reference+types+and+value+types+Re: why are there reference types and value types? <p>Good article from MSDN refering the advantages and disadvantages of both value and reference types.Please go through</p> <p><a href="http://msdn.microsoft.com/en-us/magazine/cc301569.aspx" title="http://msdn.microsoft.com/en-us/magazine/cc301569.aspx" target="_blank">http://msdn.microsoft.com/en-us/magazine/cc301569.aspx</a>&nbsp;</p> 2012-02-12T14:10:00-05:004828428http://forums.asp.net/p/1768667/4828428.aspx/1?Re+why+are+there+reference+types+and+value+types+Re: why are there reference types and value types? <p>hi</p> <p>it will&nbsp;shown the difference between value type and reference type</p> <p><a href="http://csharpektroncmssql.blogspot.in/2011/11/diffrece-between-value-type-and.html">http://csharpektroncmssql.blogspot.in/2011/11/diffrece-between-value-type-and.html</a></p> 2012-02-12T14:23:29-05:004828468http://forums.asp.net/p/1768667/4828468.aspx/1?Re+why+are+there+reference+types+and+value+types+Re: why are there reference types and value types? <p>@ <a title="newbie2C#" href="http://forums.asp.net/members/newbie2C%23.aspx">newbie2C#</a></p> <p>this is the simplified answer.</p> <p>(a) the feature is not unique to c#</p> <p>(b) hardware architecture matters (see (c), below).</p> <p>(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.&nbsp;</p> <p style="padding-left:30px"><a href="http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx">http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx</a>&nbsp;&quot;Value Types (C# Reference)&quot;</p> <blockquote dir="ltr" style="margin-right:0px">&lt;div class=&quot;introduction&quot;&gt; <p>The value types consist of two main categories:</p> <ul> <li> <p><a href="http://msdn.microsoft.com/en-us/library/ah19swz4.aspx">Structs</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/sbbt4032.aspx">Enumerations</a></p> </li></ul> <p>Structs fall into these categories:</p> <ul> <li> <p>Numeric types</p> <ul> <li> <p><a href="http://msdn.microsoft.com/en-us/library/exx3b86w.aspx">Integral types</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/9ahet949.aspx">Floating-point types</a></p> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/364x0z75.aspx">decimal</a></p> </li></ul> </li><li> <p><a href="http://msdn.microsoft.com/en-us/library/c8f5xwh7.aspx">bool</a></p> </li><li> <p>User defined structs.</p> </li></ul> &lt;/div&gt; </blockquote> <p>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.&nbsp; 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.</p> <p>g.</p> <p>*&nbsp;&nbsp; if you do not have LINQPad 4:</p> <p>TOOLS ... get yourself a FREE copy of LINQPad 4 (<a href="http://linqpad.net/">http://linqpad.net</a>) .. 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.</p> <p>LINQPad 4 supports c#, F#, SQL, vb.</p> 2012-02-12T15:30:01-05:004828474http://forums.asp.net/p/1768667/4828474.aspx/1?Re+why+are+there+reference+types+and+value+types+Re: why are there reference types and value types? <p>P.S.:&nbsp; 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.&nbsp; 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.</p> <p>you may find this interesting:</p> <p><a href="http://stackoverflow.com/questions/436211/is-everything-in-net-an-object">http://stackoverflow.com/questions/436211/is-everything-in-net-an-object</a></p> 2012-02-12T15:35:26-05:00