Created
December 30, 2017 11:28
-
-
Save Ibro/327c7482b7ecba4a52b1ef02e30a15e9 to your computer and use it in GitHub Desktop.
C# 7 - Return reference - https://codingblast.com/csharp-7-return-reference-local-reference/
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
public class RefLocals | |
{ | |
private int _age = 15; | |
private int[] _numbers = { 3, 2, 5, 4 }; | |
public void ReferenceToField() | |
{ | |
ref int someReferenceToAge = ref _age; | |
someReferenceToAge = 45; | |
ref int secondElement = ref _numbers[1]; | |
secondElement = 33; | |
} | |
public void PrintAge() | |
{ | |
Console.WriteLine($"Age: {_age}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment