<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - differnence between Ref and Out</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - differnence between Ref and Out</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Mon, 20 May 2013 21:33:48 GMT</pubDate>
	<lastBuildDate>Mon, 20 May 2013 21:33:48 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>7</c9:totalResults>
	<c9:pageCount>-7</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>Hi, I am learning C# and i was wondering when you would use Out as opposed to Ref in a function call. I don't quite understand. I understand why &amp; when you would use Ref but not Out.</p><p>&nbsp;</p><p>Gregor</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/4881c12e00a14a8f9b629f5300f7afca#4881c12e00a14a8f9b629f5300f7afca</link>
		<pubDate>Sat, 03 Sep 2011 15:01:47 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/4881c12e00a14a8f9b629f5300f7afca#4881c12e00a14a8f9b629f5300f7afca</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>In C#, ref and out are the same, except that if you use out, the called method is required to initialize the value before it can return.</p><p>Use out if the called method doesn't care about the parameter's initial value, and use ref if you want to pass a value both in (the called method actually uses the value) and out (the calling method wants to use the updated value).</p><p>In neither case is the value boxed/unboxed. Internally it merely uses a pointer to the value instead of passing it by value (just like passing by ref in C&#43;&#43;).</p><p>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/12f1437f92c64bd39c5e9f5301448d36#12f1437f92c64bd39c5e9f5301448d36</link>
		<pubDate>Sat, 03 Sep 2011 19:41:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/12f1437f92c64bd39c5e9f5301448d36#12f1437f92c64bd39c5e9f5301448d36</guid>
		<dc:creator>BitFlipper</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/BitFlipper/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>As BitFlipper said, with out the method is required to set a value before it returns.</p><p><pre class="brush: csharp">// This function won't compile because value isn't set on all code paths
void Foo(out int value)
{
}

// Whereas this is fine even though value isn't set.
void Bar(ref int value)
{
}</pre></p><p>It also makes a difference on the calling side, however. Out parameters don't need to be initialized before passing them to a function:</p><p><pre class="brush: csharp">void Test()
{
    int n;
    SomeFunc(ref n); // This won't compile; n is uninitialized.
    SomeOtherFunc(out n); // Whereas this is fine, even if n is uninitialized
    // n is guaranteed to have a value after the call to Foo, because
    // the function is required to assign it a value before returning.
}</pre></p><p>Basically, use ref when you need to pass a value in and get a different value out, and use out when you only need to get a value out.</p><p>In general, try to avoid using ref/out parameters, because they lead to code that doesn't compose well. Sometimes it's unavoidable, but always try to find an alternative solution.</p><p>Just in case (since this is a common point of confusion): you do <em>not </em>need to use ref to be able to modify a parameter of a reference type (class) inside a function. With reference types you already passing a reference. Passing a reference type with ref means you pass a reference to a reference, which is only needed if you want to return a completely different instance to the caller.</p><p><pre class="brush: csharp">class Foo
{
    public string Bar { get; set; }
}

void ModifyFoo(Foo value)
{
    value.Bar = &quot;hello&quot;; // The caller will see this change, even without ref
    value = new Foo(); // But the caller will *not* see this change; it doesn't get the new instance.
}

void ReplaceFoo(ref Foo value)
{
    value = new Foo(); // With ref, the caller will see this change and get the new instance.
    // I could've used out here, since we don't use the value that was passed in.
}</pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/53fe313f5ea1474b9a7e9f54004068d7#53fe313f5ea1474b9a7e9f54004068d7</link>
		<pubDate>Sun, 04 Sep 2011 03:54:30 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/53fe313f5ea1474b9a7e9f54004068d7#53fe313f5ea1474b9a7e9f54004068d7</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/differnence-between-Ref-and-Out#c53fe313f5ea1474b9a7e9f54004068d7">Sven Groot</a>: Sorry, &quot;references types are already passed by reference&quot; is simply wrong. Without the use of ref or out you are passing by value. What you are passing by value <strong>is a reference</strong>. It's a bit of a nit, because the rest of what you said is correct, but this is one that really should be understood.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/ef4c049153df47ecaae79f5400db6d25#ef4c049153df47ecaae79f5400db6d25</link>
		<pubDate>Sun, 04 Sep 2011 13:18:54 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/ef4c049153df47ecaae79f5400db6d25#ef4c049153df47ecaae79f5400db6d25</guid>
		<dc:creator>William Kempf</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/wkempf/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/differnence-between-Ref-and-Out#cef4c049153df47ecaae79f5400db6d25">wkempf</a>: Thanks, I updated my wording a bit.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/96b52d0794a64f5887469f5400fbb87d#96b52d0794a64f5887469f5400fbb87d</link>
		<pubDate>Sun, 04 Sep 2011 15:16:29 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/96b52d0794a64f5887469f5400fbb87d#96b52d0794a64f5887469f5400fbb87d</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>Ok thanks alot <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/8eb4a37146be45d0bc519f5400fdfeb0#8eb4a37146be45d0bc519f5400fdfeb0</link>
		<pubDate>Sun, 04 Sep 2011 15:24:46 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/8eb4a37146be45d0bc519f5400fdfeb0#8eb4a37146be45d0bc519f5400fdfeb0</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - differnence between Ref and Out</title>
		<description><![CDATA[<p>&quot;out object result&quot; is a way of saying that the function will generate a new object that the caller can play with if the method is called. It's basically an additional return type that the method has, so it can return more than one thing at a time.</p><p>&quot;ref object result&quot; means you're going to give the method a variable, but allow the method to not only change the variable by calling its methods and settings its fields, but also allow the method to set the variable from which object came. This is like a sub-function setting a local variable in a parent method.</p><p>&nbsp;</p><p>Consider the following code:</p><p>object myObj = new object(); // line 1<br>foo(ref myObj); // line 2<br>// line 3</p><p>line1 initializes myObj. Line2 potentially modifies or changes myObj (it behaves like myObj = someFunc(myObj), it could either change myObj and return myObj, it could return null or it could return an entirely new object).</p><p>&nbsp;</p><p>Consider now the following code:</p><p>object myObj = new object(); // line 1<br>foo(out myObj); // line 2<br>// line 3</p><p>line1 initializes myObj as before. Line2 now throws away the previous value of myObj. During line2 myObj is set to a completely new value. This is behaving like myObj = someFunc().</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/e951b40b714049b780339f55008d76c9#e951b40b714049b780339f55008d76c9</link>
		<pubDate>Mon, 05 Sep 2011 08:35:03 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/differnence-between-Ref-and-Out/e951b40b714049b780339f55008d76c9#e951b40b714049b780339f55008d76c9</guid>
		<dc:creator>evildictaitor</dc:creator>
		<slash:comments>7</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/evildictaitor/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>