为什么ICollection< T>实现IEnumerable< T>和IEnumerable [英] Why does ICollection<T> implement both IEnumerable<T> and IEnumerable
本文介绍了为什么ICollection< T>实现IEnumerable< T>和IEnumerable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ICollection
既实现 IEnumerable
并且 IEnumerable
? 这是什么目的? IEnumerable
好处 ICollection< T>
?
解决方案
非通用接口用于向后兼容。如果你使用泛型编写代码并想将你的集合传递给一些用.NET 1.0编写的模块(它没有泛型),你仍然希望它成功,并且你希望旧的方法能够遍历它。 / p>
Why does ICollection<T>
implement both IEnumerable<T>
and IEnumerable
?
What is the purpose of this? How does IEnumerable
benefit ICollection<T>
?
解决方案
The non-generic interface is for backward compatibility. If you write code using generics and want to pass your collection to some module written in .NET 1.0 (which doesn't have generics) you still want this to succeed, and you want the old method to be able to iterate through it.
这篇关于为什么ICollection< T>实现IEnumerable< T>和IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文