Last active
October 21, 2016 08:11
-
-
Save NineMvp/bf69b29eb47e4605193180c4802ee64c to your computer and use it in GitHub Desktop.
Return Ref Local
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
static void Main() | |
{ | |
var pers = new int[] { 100, 101, 102, 109 }; | |
ref var index2 = ref getValue(pers, 2); | |
Console.WriteLine($"index 2 before = { index2 } "); // 102 | |
index2 += 5; | |
Console.WriteLine($"index 2 after = { index2 } "); //107 | |
Console.WriteLine($"index 2 after = { pers[2] } "); //107 | |
} | |
static ref int getValue(int[] items, int idx) => ref items[idx]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment