如何在 C# 7.2 中强制 ref readonly 的只读性?

How do I enforce readonlyness of ref readonly in C# 7.2?

我想写一个返回 ref 的方法 a ref readonly as described: "The feature allows a member to return variables by reference without exposing them to mutations."

不幸的是,我的代码编译并进行了这样的修改。我如何确保它不能被修改?出于充分的理由,它是只读的。我预计会出现编译器错误。我还应该做些什么吗? 200修改为201,我不要那个

internal class TryClass
{
    private static int _result = 0;

    public static ref readonly int Multiply(int a, int b)
    {
        _result = a * b;
        return ref _result;
    }
}

internal class Program
{
    private static void Main(string[] args)
    {
        int x = 10;
        int y = 20;
        var rez = TryClass.Multiply(x, y);
        rez++;
        Console.WriteLine(rez);
        Console.ReadLine();
    }
}

根据评论。这是解决方案。我得到了我期望的编译器错误:“严重性代码描述项目文件行抑制状态 错误 CS8329 无法将方法 'TryClass.Multiply(int, int)' 用作引用或输出值,因为它是只读变量

internal class Program
{
    private static void Main(string[] args)
    {
        int x = 10;
        int y = 20;
        ref readonly var rez = ref TryClass.Multiply(x, y);
        rez++;
        Console.WriteLine(rez);
        TryClass.DoAfter();
        Console.ReadLine();
    }
}