我们可以在ienumerable中添加或删除但在ienumerable内部返回ienumerator只有为什么ienumerable允许集合修改 [英] we can add or delete in ienumerable but in ienumerable internally returns ienumerator only why ienumerable allows collection modify

查看:131
本文介绍了我们可以在ienumerable中添加或删除但在ienumerable内部返回ienumerator只有为什么ienumerable允许集合修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Frends,

有非常基本的疑问,要求你帮助理解。



我们可以在不可数的情况下添加或删除,但是在ienumerable内部返回ienumerater只有为什么ienumerable允许集合修改。

和为什么ienumerator不允许修改。



或为什么ienumerater是readonly。



谢谢

Raja

Hi Frends ,
had very basic doubt , requesting you help in understand.

we can add or delete in ienumerable ,but in ienumerable internally returns ienumerater only why ienumerable allows collection modify.
and why ienumerator not allows modify.

or why ienumerater is readonly.

Thanks
Raja

推荐答案





首先,IEnumerable和IEnumerator都是接口。您可以将IEnumerable视为一个容器,其中包含一个返回IEnumeator类型对象的方法。



其次,当您创建自己的自定义集合类时,想要迭代然后你必须从IEnumerable派生来支持迭代那个集合类。



你还可以在你的集合类中编写GetEnumerator方法,它返回IEnumerator对象它可以帮助您或提供基本信息。



如1)迭代集合的当前对象是什么,2)MoveNext()方法 - 是否有更多的元素迭代的集合??,3)和Reset() - 重置迭代器指针。



希望这有帮助!
Hi,

First of all IEnumerable and IEnumerator are both interfaces. You can think of IEnumerable as a container which contains one method which returns you IEnumeator type of object.

Second, when you are creating your own custom collection class on which you want to iterate then you must derive from IEnumerable to support Iteration over that collection class.

And further you can write the GetEnumerator method in your collection class which returns you IEnumerator object which helps you or provide basic info.

like 1) what is current object which iterating over the collection, 2) MoveNext() method -- are there more elements in collection for iteration??, 3) And Reset() -- resets the iterator pointer.

Hope this helps!


这篇关于我们可以在ienumerable中添加或删除但在ienumerable内部返回ienumerator只有为什么ienumerable允许集合修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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