Skip to content

Instantly share code, notes, and snippets.

@marcusshepp
Created May 8, 2019 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusshepp/32a901f83e557252e312382d7332ea42 to your computer and use it in GitHub Desktop.
Save marcusshepp/32a901f83e557252e312382d7332ea42 to your computer and use it in GitHub Desktop.
Passing a var by reference in C#
using System;
public class Program
{
public static void Main()
{
bool foo = false;
Console.WriteLine("foo 1: ");
Console.WriteLine(foo);
changeFoo(ref foo);
Console.WriteLine("foo 2: ", foo);
Console.WriteLine(foo);
}
private static void changeFoo(ref bool fooRef)
{
fooRef = true;
}
}
// output
// foo 1:
// false
// foo 2:
// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment