Created
April 27, 2012 12:53
-
-
Save TryJSIL/2508954 to your computer and use it in GitHub Desktop.
Ref Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class Program { | |
public static void Increment (ref int x) { | |
x += 1; | |
} | |
public static void IncrementTwice (ref int x) { | |
Increment(ref x); | |
Increment(ref x); | |
} | |
public static int Incremented (int x) { | |
Increment(ref x); | |
return x; | |
} | |
public static void Main (string[] args) { | |
int a = 0; | |
Console.WriteLine("a = {0}", a); | |
Increment(ref a); | |
Console.WriteLine("a = {0}, a + 1 = {1}", a, Incremented(a)); | |
IncrementTwice(ref a); | |
Console.WriteLine("a = {0}", a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment