Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created May 5, 2018 22:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save christiannagel/25246716468cfaa34a0ba3f6692a6137 to your computer and use it in GitHub Desktop.
ref returns, ref locals, ref readonly, and ref struct with C# 7
// ref returns and ref locals with C# 7.0
int[] _numbers = { 3, 7, 11, 15, 21 };
public ref int GetNumber(int index)
{
return ref _numbers[index];
}
// ref readonly with C# 7.2
int[] _numbers = { 3, 7, 11, 15, 21 };
public ref readonly int GetNumber(int index)
{
return ref _numbers[index];
}
// ref struct with C# 7.2
ref struct OnlyOnTheStack
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment