为什么名单< T>实施IReadOnlyList< T>在.NET 4.5? [英] Why does List<T> implement IReadOnlyList<T> in .NET 4.5?

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

问题描述

为什么名单,其中,T> 实施 IReadOnlyList< T> 在.NET 4.5

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

名单,其中,T&GT; 不是只读...

推荐答案

由于名单,其中,T&GT; 实现了所有必要的方法/属性/等。 (然后一些) IReadOnlyList&LT的; T&GT; 。接口是一个合同,说:我可以做的至少的这些事情。

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&LT; T&GT; 表示,重新presents元素的只读集合。

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

这是正确的。有在该界面没有mutator方法。这就是只读手段,对不对? IReadOnlyList&LT; T&GT; 采用的是典型(合同)的方式,而不是作为一个的标记

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.

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

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