为什么 List&lt;T&gt;实现 IReadOnlyList<T>;在 .NET 4.5 中? [英] Why does List&lt;T&gt; implement IReadOnlyList&lt;T&gt; in .NET 4.5?

查看:24
本文介绍了为什么 List&lt;T&gt;实现 IReadOnlyList<T>;在 .NET 4.5 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么List要在.NET 4.5中实现IReadOnlyList?

Why does List<T> implement IReadOnlyList<T> in .NET 4.5?

List 不是只读的...

推荐答案

因为 List 实现了所有必要的方法/属性/等.(然后是一些)IReadOnlyList.接口是一种契约,上面写着我至少可以做这些事情."

Because List<T> implements all of the necessary methods/properties/etc. (and then some) of IReadOnlyList<T>. An interface is a contract that says "I can do at least these things."

IReadOnlyList 的文档说它代表一个只读的元素集合.

The documentation for IReadOnlyList<T> says it represents a read-only collection of elements.

没错.该接口中没有mutator方法.这就是只读的意思,对吧?IReadOnlyList 以典型"(合同)方式使用,而不是作为 标记.

That's right. There are no mutator methods in that interface. That's what read-only means, right? IReadOnlyList<T> is used in the "typical" (contract) way, not as a marker.

这篇关于为什么 List&lt;T&gt;实现 IReadOnlyList<T>;在 .NET 4.5 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆