<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Fun With the &#8220;ref&#8221; Keyword</title>
	<atom:link href="http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/feed/" rel="self" type="application/rss+xml" />
	<link>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/</link>
	<description>Hurdles in .NET WinForms Development</description>
	<lastBuildDate>Mon, 25 Jan 2010 20:50:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Ken</title>
		<link>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/#comment-7</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Wed, 04 Mar 2009 03:48:37 +0000</pubDate>
		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=147#comment-7</guid>
		<description>As I mentioned at the top, in C#, *everything* is passed by value unless the ref keyword is used.  But parameter passing works differently depending on if you&#039;re passing a value type or reference type.

Value types are structs, enums, bool and numeric types.  Reference types (pointers) are basically everything else.

Passing Value Type by Value:  A copy of the memory used to store the value type is created.  The value type that was passed to the method will not be affected by anything that happens within the method.  There are two independent copies of the data.

Passing Value Type by Reference:  A pointer to the Value Type&#039;s memory is passed.  Changing the value type within the method affects the value type that was passed to the method because they point to the same thing.

Passing Reference Type by Value:  A pointer to some memory is copied.  There will be two pointers to the same memory location.  Redirecting one of the pointers to null, for example, will not effect the other.

Passing Reference Type by Reference:  The same pointer is passed to the method.  Whatever happens inside the method affects the object on the outside of the method.

That&#039;s the jist of it.  I think &lt;a href=&quot;http://www.yoda.arachsys.com/csharp/parameters.html&quot; rel=&quot;nofollow&quot;&gt;this article&lt;/a&gt; does a better job explaining than I can, but the important thing to take away is that there are four possible ways to pass parameters.  Knowing the subtleties of each is key.</description>
		<content:encoded><![CDATA[<p>As I mentioned at the top, in C#, *everything* is passed by value unless the ref keyword is used.  But parameter passing works differently depending on if you&#8217;re passing a value type or reference type.</p>
<p>Value types are structs, enums, bool and numeric types.  Reference types (pointers) are basically everything else.</p>
<p>Passing Value Type by Value:  A copy of the memory used to store the value type is created.  The value type that was passed to the method will not be affected by anything that happens within the method.  There are two independent copies of the data.</p>
<p>Passing Value Type by Reference:  A pointer to the Value Type&#8217;s memory is passed.  Changing the value type within the method affects the value type that was passed to the method because they point to the same thing.</p>
<p>Passing Reference Type by Value:  A pointer to some memory is copied.  There will be two pointers to the same memory location.  Redirecting one of the pointers to null, for example, will not effect the other.</p>
<p>Passing Reference Type by Reference:  The same pointer is passed to the method.  Whatever happens inside the method affects the object on the outside of the method.</p>
<p>That&#8217;s the jist of it.  I think <a href="http://www.yoda.arachsys.com/csharp/parameters.html" rel="nofollow">this article</a> does a better job explaining than I can, but the important thing to take away is that there are four possible ways to pass parameters.  Knowing the subtleties of each is key.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/#comment-5</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Tue, 03 Mar 2009 15:34:46 +0000</pubDate>
		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=147#comment-5</guid>
		<description>This is one thing I never liked about Java (and since C# is similar to Java in so many ways...).  I learned to code in C and when coding in C you know exactly when you&#039;re using a variable or a pointer to that variable.  EVERYTHING is passed by value.  If you want to pass by reference you pass the value of the pointer (or reference).

What makes the modern &lt;acronym title=&quot;Object Oriented&quot;&gt;OO&lt;/acronym&gt; languages confusing is that you don&#039;t need to indicate that you&#039;re using a reference by placing a * before the variable declaration and dereference it before each use.  It&#039;s easy to forget what&#039;s going on behind the scenes when the language hides this from the coder.

Pizer&#039;s link was indeed helpful.  I like that it covered the ever ignored &lt;i&gt;struct&lt;/i&gt;.  I&#039;ve always thought it was a poor choice of C# to define DateTime with capital letters since it&#039;s a struct and not a class.  It&#039;s immutable just like a string.</description>
		<content:encoded><![CDATA[<p>This is one thing I never liked about Java (and since C# is similar to Java in so many ways&#8230;).  I learned to code in C and when coding in C you know exactly when you&#8217;re using a variable or a pointer to that variable.  EVERYTHING is passed by value.  If you want to pass by reference you pass the value of the pointer (or reference).</p>
<p>What makes the modern <acronym title="Object Oriented">OO</acronym> languages confusing is that you don&#8217;t need to indicate that you&#8217;re using a reference by placing a * before the variable declaration and dereference it before each use.  It&#8217;s easy to forget what&#8217;s going on behind the scenes when the language hides this from the coder.</p>
<p>Pizer&#8217;s link was indeed helpful.  I like that it covered the ever ignored <i>struct</i>.  I&#8217;ve always thought it was a poor choice of C# to define DateTime with capital letters since it&#8217;s a struct and not a class.  It&#8217;s immutable just like a string.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/#comment-3</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Wed, 04 Feb 2009 15:13:04 +0000</pubDate>
		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=147#comment-3</guid>
		<description>Ahhh haaa!!  I&#039;ll hand it to you pizer, you&#039;re right on all counts (and what better way to learn than with an open forum, right??).  Your explanation on scenario #2 makes sense.  Also, the link you sent breaks down the ideas of value and reference very clearly.  Into Delicious it goes....Good article!  Thanks for the help!</description>
		<content:encoded><![CDATA[<p>Ahhh haaa!!  I&#8217;ll hand it to you pizer, you&#8217;re right on all counts (and what better way to learn than with an open forum, right??).  Your explanation on scenario #2 makes sense.  Also, the link you sent breaks down the ideas of value and reference very clearly.  Into Delicious it goes&#8230;.Good article!  Thanks for the help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pizer</title>
		<link>http://kenkopczyk.com/2009/02/03/fun-with-the-ref-keyword/#comment-2</link>
		<dc:creator>pizer</dc:creator>
		<pubDate>Wed, 04 Feb 2009 11:51:12 +0000</pubDate>
		<guid isPermaLink="false">http://kkopczyk.wordpress.com/?p=147#comment-2</guid>
		<description>Are you sure you understand the different kinds of types and parameters? It seems you don&#039;t get the fundamental difference between value types and reference types. Check out:

&lt;a href=&quot;http://www.yoda.arachsys.com/csharp/parameters.html&quot; rel=&quot;nofollow&quot;&gt;C# parameters&lt;/a&gt;

#1 Just accept this rule. A property is not an object that can be bound to a reference. It&#039;s just syntactic sugar for hiding function calls.

#2 It tjhis was allowed you would have a hole in the type system because DoSomethingSuper would be allowed to change mySuperDataRow and make it point to some other subclass object (derived from DataRow) that is NOT a SuperDataRow.

What do you think &quot;mySuperDataRow&quot; is? It already is a reference to a SuperDataRow object.

-P</description>
		<content:encoded><![CDATA[<p>Are you sure you understand the different kinds of types and parameters? It seems you don&#8217;t get the fundamental difference between value types and reference types. Check out:</p>
<p><a href="http://www.yoda.arachsys.com/csharp/parameters.html" rel="nofollow">C# parameters</a></p>
<p>#1 Just accept this rule. A property is not an object that can be bound to a reference. It&#8217;s just syntactic sugar for hiding function calls.</p>
<p>#2 It tjhis was allowed you would have a hole in the type system because DoSomethingSuper would be allowed to change mySuperDataRow and make it point to some other subclass object (derived from DataRow) that is NOT a SuperDataRow.</p>
<p>What do you think &#8220;mySuperDataRow&#8221; is? It already is a reference to a SuperDataRow object.</p>
<p>-P</p>
]]></content:encoded>
	</item>
</channel>
</rss>
