471,318 Members | 3,268 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Sortable collection

_DS
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?

Jan 29 '06 #1
10 5093
_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
Jan 29 '06 #2
"_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.

Jan 29 '06 #3
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.

Jan 30 '06 #4
_DS,

You will probably want to implement IComparable in the class for which you
are building the CollectionBase implementation - not in the collection but in
the class the collection will hold.

And there's nothing that says you couldn't then create your own Sort command
in your custom collection, but John is correct, there is one that you can use.

In either case, writing your own sort or using InnerList.Sort(), you should
implement IComparable so that the sort can do the comparisons that are
required.

HTH
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Jon Skeet [C# MVP]" wrote:
_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

Jan 30 '06 #5
Some suggested reading for you, Nick:

http://www.dalepreston.com/Blog/2005...by-insult.html

HTH
--
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.

Jan 30 '06 #6
One RTFM at the end of a post containing the answer to his question plus the
constructive advice about how to go about answering future questions hardly
constitutes motivation by insult.

Surely you must agree that to post without even looking up the members of
the class you are using indicates either laziness or poor problem solving
skills.

"Dale" <da******@nospam.nospam> wrote in message
news:AE**********************************@microsof t.com...
Some suggested reading for you, Nick:

http://www.dalepreston.com/Blog/2005...by-insult.html

HTH
--
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.

Jan 30 '06 #7
_DS
On Sun, 29 Jan 2006 08:00:46 GMT, "Nick Hounsome"
I honestly do not understand the thinking process of some people who post on
these groups.


Here's my thinking process: You should find those guys who beat you
up on the playground and give them a good scolding. I do want to
thank you for my heightened appreciation for the Dale Prestons and
John Skeets of the world. Usenet would be a sorry place...

Dale and John, thanks again. I'll eventually move to generics, but I
had already written a class that derived from ArrayList and
implemented compare functions, etc. I was going to change to derive
from CollectionBase instead. I did miss the InnerList property,
partly as I was looking for functions. But more because I thought
that CollectionBase was further down in the inheritance hierarchy and
that ArrayList was derived from CollectionBase. I'll check into that.

Jan 31 '06 #8

"_DS" <_D*@Nospamforme.com> wrote in message
news:1j********************************@4ax.com...
On Sun, 29 Jan 2006 08:00:46 GMT, "Nick Hounsome"
I honestly do not understand the thinking process of some people who post
on
these groups.
Here's my thinking process: You should find those guys who beat you
up on the playground and give them a good scolding. I do want to
thank you for my heightened appreciation for the Dale Prestons and
John Skeets of the world. Usenet would be a sorry place...


Hypocrit! This is way more of a flame than I dished out.

Dale and John, thanks again. I'll eventually move to generics, but I
had already written a class that derived from ArrayList and
implemented compare functions, etc. I was going to change to derive
from CollectionBase instead. I did miss the InnerList property,
partly as I was looking for functions.
Hopefully thanks to my comment you have now learned to look for protected
properties.
But more because I thought
that CollectionBase was further down in the inheritance hierarchy and
that ArrayList was derived from CollectionBase.


Why? Inheritance is shown quite clearly near the top of the doc page.

You are just proving my point that a few moments careful reading of the
documentation about a class is more time efficient than posting.
Jan 31 '06 #9
_DS
On Tue, 31 Jan 2006 08:09:33 GMT, "Nick Hounsome"
<nh***@nickhounsome.me.uk> wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:1j********************************@4ax.com.. .
On Sun, 29 Jan 2006 08:00:46 GMT, "Nick Hounsome"
I honestly do not understand the thinking process of some people who post
on
these groups.
Here's my thinking process: You should find those guys who beat you
up on the playground and give them a good scolding. I do want to
thank you for my heightened appreciation for the Dale Prestons and
John Skeets of the world. Usenet would be a sorry place...


Hypocrit! This is way more of a flame than I dished out.


More of a flame than your "Read The Fucking Manual" rant? (or did you
not know what RTFM means). You can dish it out, I'll give you that.
Hopefully thanks to my comment you have now learned to look for protected
properties.


Hopefully you'll try decaf. In the future, consider what you're
saying and please don't 'Help" me any more. I thought this group was
relatively free of flamers.

DS
Feb 4 '06 #10

"_DS" <_D*@nomail.com> wrote in message news:8f********************************@4ax.com...
On Tue, 31 Jan 2006 08:09:33 GMT, "Nick Hounsome"
<nh***@nickhounsome.me.uk> wrote:
"_DS" <_D*@Nospamforme.com> wrote in message
news:1j********************************@4ax.com. .. <snip>Hypocrit! This is way more of a flame than I dished out.


More of a flame than your "Read The Fucking Manual" rant? (or did you
not know what RTFM means). You can dish it out, I'll give you that.


Perhaps he meant "Read the FINE Manual" and you just took it wrong?!?!

:^)

OK...I'll go away now

Bill
Feb 5 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by suz | last post: by
3 posts views Thread by TPhelps | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.