【问题标题】:C# 7.2 proxy "by-value returns"C# 7.2 代理“按值返回”
【发布时间】:2018-12-17 17:37:28
【问题描述】:

我正在尝试编写和代理具有

的 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);
}

我明白了:

按值返回只能用于按值返回的方法

这里有什么问题?以及如何解决这个问题?

【问题讨论】:

  • public ref readonly T ItemRef(int index) =&gt; ref Value.ItemRef(index);?
  • 太棒了,编译!你能发布答案吗

标签: c# c#-7.2


【解决方案1】:

你在隐式return之前缺少ref

public ref readonly T ItemRef(int index) => ref Value.ItemRef(index);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多