Skip to content

Instantly share code, notes, and snippets.

@marcusshepp marcusshepp/ref.cs
Created May 8, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.