C# 7 ref local and ref return

CSharp · Console

/Program.cs

using System;
					
public class Program
{
    static int _number = 10;

    public static void Main()
    {
        ref int n = ref RefReturn(); // ref 區域變數
        n = 20;

        Console.WriteLine(_number); // 輸出 "20"
    }

    static ref int RefReturn() // ref 回傳值
    {
        return ref _number;
    }
}
;