C# 7.2 代理 "by-value returns"
C# 7.2 proxy "by-value returns"
我正在尝试编写和代理具有
的 ImmutableList
public ref readonly T ItemRef(int index);
我试试:
public class MyImmutableList<T> {
public readonly ImmutableList<T> Value;
...
public ref readonly T ItemRef(int index) => Value.ItemRef(index);
}
我得到:
By-value returns may only be used in methods that return by value
这里有什么问题吗?以及如何解决这个问题?
您在隐式 return
之前缺少 ref
:
public ref readonly T ItemRef(int index) => ref Value.ItemRef(index);
我正在尝试编写和代理具有
的 ImmutableListpublic ref readonly T ItemRef(int index);
我试试:
public class MyImmutableList<T> {
public readonly ImmutableList<T> Value;
...
public ref readonly T ItemRef(int index) => Value.ItemRef(index);
}
我得到:
By-value returns may only be used in methods that return by value
这里有什么问题吗?以及如何解决这个问题?
您在隐式 return
之前缺少 ref
:
public ref readonly T ItemRef(int index) => ref Value.ItemRef(index);