gpt4 book ai didi

c# - 为什么 ReadOnlyCollection 不是 ReadOnlyCollection

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:10 24 4
gpt4 key购买 nike

ReadOnlyCollection<T>只支持读操作。为什么 T未标有 out关键字?

最佳答案

ReadOnlyCollection supports only reading operations

它只支持读取,因为它是通用只读集合的​​基类。

Why T is not marked with out keyword?

out 关键字表示参数是协变的,只有接口(interface)和委托(delegate)可以协变。注意 ReadOnlyCollection<T>工具 IEnumerable<T>这是协变的。

关于c# - 为什么 ReadOnlyCollection<T> 不是 ReadOnlyCollection<out T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12223983/

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