Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace InOutRef { static class InOutRef { public static void In(int i) { Console.WriteLine(i); i=100; Console.WriteLine(i); } public static void Ref(ref int i) { Console.WriteLine(i); i=200; Console.WriteLine(i); } public static void Out(out int i) { //Console.WriteLine(i); //Error Unsigned Ref i=300; Console.WriteLine(i); } } class Program { static void Main(string[] args) { int i = 1; InOutRef.In(i); //passed by value (in only) Debug.Assert(i==1); InOutRef.Ref(ref i); //passed by ref (in or out) Debug.Assert(i == 200); InOutRef.Out(out i); //passed by as out ref (out only) Debug.Assert(i == 300); } } } </code></pre> <p>I can't be any more literal on my answer. The code will not remember reference chanages such as the classic Java swap <a href="https://stackoverflow.com/questions/1363186/is-it-possible-to-write-swap-method-in-java">question</a> when using <strong>in</strong>. However, when using <strong>ref</strong>, it will be similar to VB.NET as it will remember the changes <strong>in</strong> and <strong>out</strong>. If you use the <strong>out</strong> parameter it means that it must be declared before you return (this is enforced by the compiler).</p> <pre> Output: 1 //1 from main 100 //100 from in 1 //1 is NOT remembered from In 200 //200 from ref //should be 200 here but out enforces out param (not printed because commented out) 300 //300 is out only Press any key to continue . . . </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload