可收集的集合 [英] Sortable collection

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

问题描述

据我所知,创建强类型

集合的常用方法是从CollectionBase继承。但是,CollectionBase

不支持排序。实现这个的最佳方法是什么?

从ArrayList派生?

解决方案

_DS< _D *@Nospamforme.com>写道:

我知道创建强类型
集合的常用方法是从CollectionBase继承。但是,CollectionBase
不支持排序。实现这个的最佳方法是什么?
从ArrayList派生?




CollectionBase.InnerList返回一个ArrayList,所以你可以对它进行排序。


当然,在2.0中你可能不会在第一个

的地方使用CollectionBase,但是List< T> ;.


-

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

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


" _DS" < _D*@Nospamforme.com>在消息中写道

news:6q ******************************** @ 4ax.com ...

我知道创建强类型
集合的常用方法是从CollectionBase继承。但是,CollectionBase
不支持排序。实现这个的最佳方法是什么?
从ArrayList派生?




老实说,我不明白一些人的思考过程

这些团体。


这就是我的想法:


1)我想实现强类型集合所以我使用CollectionBase

2)CollectionBase帮我实现了什么?哦。这是一个名为InnerList的受保护的
受保护属性,它允许访问使用

来实现集合的ArrayList。

3)我将实现通过调用InnerList.Sort进行排序()


我看不出它是如何变得更容易。

最困难的部分是在第一个中找到CollectionBase地方甚至那个

自然而然地说我想收藏东西所以

收藏品名称空间中的内容是什么?


我不喜欢火焰但是RTFM老兄 - 在100分之内发布了99次,比发布时间更快,你学到了额外的东西,除了你的特定问题之外>
片刻。


如果你不喜欢火焰,那么为什么呢?

- -

Dale Preston

MCAD C#

MCSE,MCDBA

" Nick Hounsome"写道:

" _DS" < _D*@Nospamforme.com>在消息中写道
新闻:6q ******************************** @ 4ax.com ... < blockquote class =post_quotes>我知道创建强类型
集合的常用方法是从CollectionBase继承。但是,CollectionBase
不支持排序。实现这个的最佳方法是什么?
从ArrayList派生?



我真的不理解那些发布在这些群组上的人的思维过程。

这就是我的想法:

1)我想实现一个强类型的集合,所以我使用CollectionBase
2)CollectionBase给了我什么帮助实现这个?哦。这个名为InnerList的受保护属性可以访问用于实现集合的ArrayList。
3)我将通过调用InnerList.Sort()来实现Sort

我看不出它会变得多么简单。
最困难的部分是首先找到CollectionBase,甚至可以自然而然地说我想做收藏的东西如此
收藏品名称空间中的内容是什么?

我不喜欢火焰但是RTFM老兄 - 99次超过100次比发布更快并且你会学到额外的东西,除了你特定的
时刻之外。



I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?

解决方案

_DS <_D*@Nospamforme.com> wrote:

I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?



CollectionBase.InnerList returns an ArrayList, so you can sort that.

Of course, in 2.0 you probably wouldn''t use CollectionBase in the first
place, but List<T>.

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


"_DS" <_D*@Nospamforme.com> wrote in message
news:6q********************************@4ax.com...

I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?



I honestly do not understand the thinking process of some people who post on
these groups.

This is how I would think:

1) I want to implement a strongly typed collection so I use CollectionBase
2) What does CollectionBase give me to help implement this? Oh. there''s this
protected property called InnerList which gives access to the ArrayList used
to implement the collection.
3) I will implement Sort by calling InnerList.Sort()

I can''t see how it could be any easier.
The hardest part is finding CollectionBase in the first place and even that
comes naturally from saying to yourself "I want to do collection stuff so
what is in the Collections namespace?"

I don''t like to flame but RTFM dude - 99 times out of a 100 its quicker than
posting and you learn extra stuff beyond your particular problem of the
moment.


If you don''t like to flame, then why do it?
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Nick Hounsome" wrote:

"_DS" <_D*@Nospamforme.com> wrote in message
news:6q********************************@4ax.com...

I understand that the usual way of creating a strongly typed
collection is to inherit from CollectionBase. However, CollectionBase
does not support sorting. What is the best way to implement this?
Derive from ArrayList?



I honestly do not understand the thinking process of some people who post on
these groups.

This is how I would think:

1) I want to implement a strongly typed collection so I use CollectionBase
2) What does CollectionBase give me to help implement this? Oh. there''s this
protected property called InnerList which gives access to the ArrayList used
to implement the collection.
3) I will implement Sort by calling InnerList.Sort()

I can''t see how it could be any easier.
The hardest part is finding CollectionBase in the first place and even that
comes naturally from saying to yourself "I want to do collection stuff so
what is in the Collections namespace?"

I don''t like to flame but RTFM dude - 99 times out of a 100 its quicker than
posting and you learn extra stuff beyond your particular problem of the
moment.



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

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