使扩展IEnumerator安全的最佳方法是什么? [英] What is the best way to make extended IEnumerator safe?

查看:65
本文介绍了使扩展IEnumerator安全的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在扩展标准的IEnumerator,我只是想知道

使enumarator安全的最佳方法是什么?安全是什么意思?检测删除和

所有...

我的想法是在集合中有私人Guid状态字段,并且插入每个

时间或者从集合中删除,我只会更改guid的
。调查员只需要比较

中收到的指导与当前的指令。如果它们不同,该系列已经改变了



您对此有何看法?


谢谢你,

Sasha

Hi,

I am extending standard IEnumerator, and I was just wondering what is the
best way to make enumarator safe? What do I mean by safe? Detect deletes and
all...
My idea is to have private Guid state field in the collection, and every
time something is inserted or deleted from the collection, I will just
change the guid. Enumerator will just have to compare the guid received in
the begging to the current one. If they are different, the collection has
changed.

What are your thought on this?

Thank you,
Sasha

推荐答案

Sasha,


听起来像是一个好主意,而且它也会快速简单。

你必须要记住的唯一事情是锁定收藏品或

而不是确保指导多线程正确访问。


希望这会有所帮助。


-

- Nicholas Paldino [。 NET / C#MVP]

- nick(dot)paldino = at = exisconsulting< dot> com


" Sasha" < no@no.com>在消息中写道

news:OR ************** @ TK2MSFTNGP12.phx.gbl ...
Sasha,

That sounds like a good idea, and it would be quick and easy as well.
The only things you have to keep in mind is to lock the collections or
rather make sure that the guid is accessed correctly by multiple threads.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Sasha" <no@no.com> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...

我正在扩展标准IEnumerator,我只是想知道什么是使enumarator安全的最佳方法?安全是什么意思?检测删除
和所有...
我的想法是在集合中有私人Guid状态字段,并且每次从集合中插入或删除某些东西时,我只会
改变指导。调查员只需将乞讨中收到的指导与当前的指导进行比较。如果它们不同,那么这个系列已经改变了。

你对此有何看法?

谢谢你,
Sasha
Hi,

I am extending standard IEnumerator, and I was just wondering what is the
best way to make enumarator safe? What do I mean by safe? Detect deletes and all...
My idea is to have private Guid state field in the collection, and every
time something is inserted or deleted from the collection, I will just
change the guid. Enumerator will just have to compare the guid received in
the begging to the current one. If they are different, the collection has
changed.

What are your thought on this?

Thank you,
Sasha



Sasha写道:


我正在扩展标准的IEnumerator,我只是想知道什么是使安全者安全的最佳方法?安全是什么意思?检测
删除和所有...
Hi,

I am extending standard IEnumerator, and I was just wondering what is
the best way to make enumarator safe? What do I mean by safe? Detect
deletes and all...




为什么?



Why?


否则枚举器将具有逻辑性错误。


如果有人添加了一些内容,但我们已经通过了那个区域。我们将

错过一件物品......


保重,

Sasha


Frank Oquendo < FR **** @ acadx.com>在消息中写道

新闻:Oo ************** @ TK2MSFTNGP10.phx.gbl ...
Otherwise enumerator will have a logical error.

What if someone added some stuff, but we already passed that area. We will
miss one item...

Take Care,
Sasha

"Frank Oquendo" <fr****@acadx.com> wrote in message
news:Oo**************@TK2MSFTNGP10.phx.gbl...
Sasha写道:


我正在扩展标准的IEnumerator,我只是想知道什么是使enumarator安全的最好方法?安全是什么意思?检测
删除和所有...
Hi,

I am extending standard IEnumerator, and I was just wondering what is
the best way to make enumarator safe? What do I mean by safe? Detect
deletes and all...



为什么?



Why?



这篇关于使扩展IEnumerator安全的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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