Skip to content

Instantly share code, notes, and snippets.

@NineMvp
Last active October 21, 2016 08:11
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 NineMvp/bf69b29eb47e4605193180c4802ee64c to your computer and use it in GitHub Desktop.
Save NineMvp/bf69b29eb47e4605193180c4802ee64c to your computer and use it in GitHub Desktop.
Return Ref Local
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