Created
December 30, 2017 12:13
-
-
Save Ibro/a88d192eb7fef07557c2540ea2ecfc99 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 RefReturns | |
{ | |
public RefReturns() | |
{ | |
this._grade = 2; | |
} | |
private int _grade; | |
public void PrintGrade() | |
{ | |
Console.WriteLine($"Grade: {this._grade}"); | |
} | |
public ref int DoStuff() | |
{ | |
return ref this._grade; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
RefReturns refReturns = new RefReturns(); | |
ref int grade = ref refReturns.DoStuff(); | |
grade = 17; | |
refReturns.PrintGrade(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment