Skip to content

Instantly share code, notes, and snippets.

@TryJSIL
Created April 27, 2012 12:53
Show Gist options
  • Save TryJSIL/2508954 to your computer and use it in GitHub Desktop.
Save TryJSIL/2508954 to your computer and use it in GitHub Desktop.
Ref Parameters
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