IList的Util函数 [英] Util functions for IList

查看:57
本文介绍了IList的Util函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么没有IList的一些util函数,例如Sort()?


-

cody


免费软件工具,游戏和幽默
http://www.deutronium.de。 vu || http://www.deutronium.tk

why arent there some util functions for IList for example Sort()?

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk

推荐答案

cody< no **************** @ gmx.net>写道:
cody <no****************@gmx.net> wrote:
为什么没有IList的一些util函数,例如Sort()?
why arent there some util functions for IList for example Sort()?




我*怀疑*它是因为在每个案例中进行合理有效排序的方法取决于列表的实现。尝试使用明显的排序

链表。

性能条款中的方法很糟糕。


还有一个问题就是找出你会放置这些方法的地方,

因为他们不能在IList本身。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件



I *suspect* it''s because the way to do a reasonably efficient sort in
each case depends on the implementation of the list. Trying to sort a
linked list using the "obvious" kind of approach would be horrendous in
performance terms.

There''s also the issue of working out where you''d put such methods,
given that they couldn''t be in IList itself.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


>我*怀疑*这是因为在
> I *suspect* it''s because the way to do a reasonably efficient sort in
每种情况下进行合理有效排序的方式取决于列表的实现。尝试使用显而易见的方式对
链接列表进行排序。在表现方面,这种方法会很糟糕。


你是对的。这让我想到为什么通用IList首先需要一个索引器在



滥用它会导致可怕的性能,而且你经常看不到

内部实现。

我认为IList是一个糟糕的接口,它应该被分解为

具有较少功能的接口,这将使得实现readonly

包装容易。首先提供所有可能的方法,但是在运行时期间抛出

InvalidOperationException并不是一个好主意。

还有一个问题就是找出你应该放置这些方法的地方,
因为他们不能在IList本身。
each case depends on the implementation of the list. Trying to sort a
linked list using the "obvious" kind of approach would be horrendous in
performance terms.
You are right. This makes me think why a generic IList needs an indexer in
the first place then.
Misusing it would lead to horrible performance, and you often do not see the
internal implementation.
I consider IList a bad interface it should have be broken down into
interfaces with less functionality which would make implementing readonly
wrappers easies. Providing every possible method first, but throwing
InvalidOperationException during runtime is no good idea.
There''s also the issue of working out where you''d put such methods,
given that they couldn''t be in IList itself.




使用静态方法的ListUtil或CollectionUtil类没问题。
< br $> b $ b -

cody


免费软件工具,游戏和幽默
http://www.deutronium.de.vu || http://www.deutronium.tk



A ListUtil or CollectionUtil class with static methods would be fine.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk

cody写道:
cody wrote:
我*怀疑*这是因为在每个方法中进行合理有效的排序case取决于列表的实现。尝试使用显而易见的方式对
链接列表进行排序。
性能方面的方法很糟糕。

你是对的。这让我想到为什么一般的IList首先需要一个索引器。
滥用它会导致可怕的性能,而且你经常看不到
内部实现。
我认为IList是一个糟糕的接口,它应该被分解为具有较少功能的接口,这将使得实现readonly
包装器变得容易。首先提供所有可能的方法,但在运行时抛出InvalidOperationException并不是一个好主意。
I *suspect* it''s because the way to do a reasonably efficient sort in
each case depends on the implementation of the list. Trying to sort a
linked list using the "obvious" kind of approach would be horrendous in
performance terms.

You are right. This makes me think why a generic IList needs an indexer in
the first place then.
Misusing it would lead to horrible performance, and you often do not see the
internal implementation.
I consider IList a bad interface it should have be broken down into
interfaces with less functionality which would make implementing readonly
wrappers easies. Providing every possible method first, but throwing
InvalidOperationException during runtime is no good idea.




这将爆炸BCL的System.Collections命名空间:

看一下实现IList的类列表。



This would explode BCL''s System.Collections namespace:
Take a look at the list of classes that implement IList.

还有一个问题就是找出你要放的地方这样的方法,
因为它们不能在IList本身。
There''s also the issue of working out where you''d put such methods,
given that they couldn''t be in IList itself.




你错过了静态ArrayList.Adapter方法
为IList创建一个ArrayList包装器。

ArrayList是一个Sort-method,所以你不需要另外一个帮助类/方法



再见

Rob



You missed the static ArrayList.Adapter method
that creates an ArrayList wrapper for an IList.
ArrayList hat a Sort-method, so you do''t need
another helper classes/methods.

bye
Rob


这篇关于IList的Util函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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