gpt4 book ai didi

C# 7.2 代理 "by-value returns"

转载 作者:太空宇宙 更新时间:2023-11-03 22:43:12 26 4
gpt4 key购买 nike

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

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

关于C# 7.2 代理 "by-value returns",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51255655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com