<p>I'm looking for a clear, concise and accurate answer.  </p>

<p>Ideally as the actual answer, although links to good explanations welcome.</p>

<p>This also applies to VB.Net, but the keywords are different - <code>ByRef</code> and <code>ByVal</code>.</p>

[{'answer_id': 13061, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 2, 'selected': False, 'text': '<p><code>out</code> means that the parameter will be initialised by the method:</p>\n\n<pre><code>int result; //not initialised\n\nif( int.TryParse( "123", out result ) )\n   //result is now 123\nelse\n   //if TryParse failed result has still be \n   // initialised to its default value (0)\n</code></pre>\n\n<p><code>ref</code> will force the underlying reference to be passed:</p>\n\n<pre><code>void ChangeMyClass1( MyClass input ) {\n   input.MyProperty = "changed by 1";\n   input = null;\n   //can\'t see input anymore ... \n   // I\'ve only nulled my local scope\'s reference\n}\n\nvoid ChangeMyClass2( ref MyClass input ) {\n   input.MyProperty = "changed by 2";\n   input = null;\n   //the passed reference is now null too.\n}\n\nMyClass tester = new MyClass { MyProperty = "initial value" };\n\nChangeMyClass1( tester );\n// now tester.MyProperty is "changed by 1"\n\nChangeMyClass2( ref tester );\n// now tester is null\n</code></pre>\n'}, {'answer_id': 13070, 'author': 'sven', 'author_id': 46, 'author_profile': 'https://Stackoverflow.com/users/46', 'pm_score': 2, 'selected': False, 'text': '<p>One of my own questions at stackoverflow handles this topic too.<br>\nIt handles about <a href="https://stackoverflow.com/questions/2027/pass-by-reference-or-pass-by-value">"pass by reference" and "pass by value"</a> in different types of languages, <a href="https://stackoverflow.com/questions/2027/pass-by-reference-or-pass-by-value#2554">c# is included</a> so maybe you can find some extra information there as well.</p>\n\n<p>Basically it comes down to:</p>\n\n<ul>\n<li>ref: the parameter with the ref keyword will be passed <em>by reference</em></li>\n<li>out: the parameter with the out keyword will be treated as an <em>output parameter</em></li>\n</ul>\n\n<p>but that\'s really the most basic answer you can give, as it is a little more complex than it is stated here</p>\n'}, {'answer_id': 13100, 'author': 'Zooba', 'author_id': 891, 'author_profile': 'https://Stackoverflow.com/users/891', 'pm_score': 6, 'selected': True, 'text': '<p>By default (in C#), passing an object to a function actually passes a copy of the reference to that object. Changing the parameter itself only changes the value in the parameter, and not the variable that was specified.</p>\n\n<pre><code>void Test1(string param)\n{\n    param = "new value";\n}\n\nstring s1 = "initial value";\nTest1(s1);\n// s1 == "initial value"\n</code></pre>\n\n<p>Using <code>out</code> or <code>ref</code> passes a reference to the variable specified in the call to the function. Any changes to the value of an <code>out</code> or <code>ref</code> parameter will be passed back to the caller.</p>\n\n<p>Both <code>out</code> and <code>ref</code> behave identically except for one slight difference: <code>ref</code> parameters are required to be initialised before calling, while <code>out</code> parameters can be uninitialised. By extension, <code>ref</code> parameters are guaranteed to be initialised at the start of the method, while <code>out</code> parameters are treated as uninitialised.</p>\n\n<pre><code>void Test2(ref string param)\n{\n    param = "new value";\n}\n\nvoid Test3(out string param)\n{\n    // Use of param here will not compile\n    param = "another value";\n}\n\nstring s2 = "initial value";\nstring s3;\nTest2(ref s2);\n// s2 == "new value"\n// Test2(ref s3); // Passing ref s3 will not compile\nTest3(out s2);\n// s2 == "another value"\nTest3(out s3);\n// s3 == "another value"\n</code></pre>\n\n<p><strong>Edit</strong>: As <a href="https://stackoverflow.com/questions/13060/what-do-ref-val-and-out-mean-on-method-parameters#13105" title="dp">dp</a> points out, the difference between <code>out</code> and <code>ref</code> is only enforced by the C# compiler, not by the CLR. As far as I know, VB has no equivalent for <code>out</code> and implements <code>ref</code> (as <code>ByRef</code>) only, matching the support of the CLR.</p>\n'}, {'answer_id': 13105, 'author': 'denis phillips', 'author_id': 748, 'author_profile': 'https://Stackoverflow.com/users/748', 'pm_score': 3, 'selected': False, 'text': '<p>One additional note about ref vs. out: The distinction between the two is enforced by the C# compiler. The CLR does not distinguish between between out and ref. This means that you cannot have two methods whose signatures differ only by an out or ref</p>\n\n<pre><code>void foo(int value) {}\n\n// Only one of the following would be allowed\n\n// valid to overload with ref\nvoid foo(ref int value) {}\n\n// OR with out\nvoid foo(out int value) {}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/13060', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/905/']