Created
May 8, 2019 15:22
-
-
Save marcusshepp/32a901f83e557252e312382d7332ea42 to your computer and use it in GitHub Desktop.
Passing a var by reference in C#
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 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