If I create a collection and add members using the Add() method, is is
guarenteed that the members will be returned in the same order that they
were added, if:
i) I enumerate using a foreach loop?
ii) I index from 0 to Count-1 using a for loop?
Cheers,
Mike 8 6511 -----Original Message----- If I create a collection and add members using the Add()
method, is isguarenteed that the members will be returned in the same
order that theywere added, if:
i) I enumerate using a foreach loop? ii) I index from 0 to Count-1 using a for loop?
No, it's not. Some collections are ordered, and others
are not: it depends on the semantics of the collection.
Some collections, such as ArrayList will return the
collection in order. Others such as Hashtable will return
items according to their hash value; Dictionary will sort
by the key value.
-mark
> >If I create a collection and add members using the Add() method, is isguarenteed that the members will be returned in the same order that theywere added, if:
i) I enumerate using a foreach loop? ii) I index from 0 to Count-1 using a for loop?
No, it's not. Some collections are ordered, and others are not: it depends on the semantics of the collection. Some collections, such as ArrayList will return the collection in order. Others such as Hashtable will return items according to their hash value; Dictionary will sort by the key value.
Thanks for your help, I understand now.
With regards to ordering, what will the behaviour be of a class that
inherits from CollectionBase?
Mike
Hello! With regards to ordering, what will the behaviour be of a class that inherits from CollectionBase?
It is ordered!
--
venlig hilsen / with regards
anders borum
--
> > With regards to ordering, what will the behaviour be of a class that inherits from CollectionBase?
It is ordered!
Thanks... how can you tell this?
Mike
Hi,
"Anders Borum" <a@b.dk> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl... Hello!
With regards to ordering, what will the behaviour be of a class that inherits from CollectionBase?
It is ordered!
I really don;t think that, CollectionBase use an ArrayList instance for
storing the values , if ArrayList is not sorted ( as Colburn's said ) then
the CollectionBase is by default not sorted.
You can sort it , though , just including a Sort method that return a new
collection sorted. This is very easy to do
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us>> wrote: With regards to ordering, what will the behaviour be of a class that inherits from CollectionBase?
It is ordered!
I really don;t think that, CollectionBase use an ArrayList instance for storing the values , if ArrayList is not sorted ( as Colburn's said ) then the CollectionBase is by default not sorted.
You can sort it , though , just including a Sort method that return a new collection sorted. This is very easy to do
There's a difference between "sorted" and "ordered". A CollectionBase
*is* ordered, but *isn't* sorted.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
> > You can sort it , though , just including a Sort method that return a
new collection sorted. This is very easy to do
There's a difference between "sorted" and "ordered". A CollectionBase *is* ordered, but *isn't* sorted.
So if CollectionBase is ordered, then all collections are ordered?
Mike
Mike <no***@hotmail.com> wrote: You can sort it , though , just including a Sort method that return a new collection sorted. This is very easy to do
There's a difference between "sorted" and "ordered". A CollectionBase *is* ordered, but *isn't* sorted.
So if CollectionBase is ordered, then all collections are ordered?
No, because not all collections derive from CollectionBase.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: GrumpyDev |
last post by:
what is the best way to implement collection
of custom entities?
|
by: Scott |
last post by:
I have a collection where the items in the collection are dates. I want to
iterate over the collection and build a value list string for the rowsource
of a listbox. The dates in the collection are...
|
by: Dan H. |
last post by:
Hello,
I have an application that requires a collection that is sorted by a double
field first, and then by a long field.
So, lets say I have an class that has 2 fields called time, priority. I...
|
by: Pavils Jurjans |
last post by:
Hello,
There's some confusion about the purpose and difference between these handy
classes...
First, both of them are holding number of key - value pairs, right? Then, I
see that there may be...
|
by: daniel li |
last post by:
I got another convert issue. This is the same project as I posted
yesterday, and received a perfect response.
The conversion threw a SupportClass for me and one of the data type is...
|
by: aa7im |
last post by:
I have a similiar thread going about this topic but I decided to break
it off into a seperate discussion.
Question:
What is the best way to determine if an object "IsNew" to a collection?
...
|
by: dx |
last post by:
Any ideas? I can't find any examples that support this.
I'm thinking a solution may be something like inherting arraylist and
containing a hashtable.
or
Inheriting NameObjectCollectionBase...
|
by: gmccallum |
last post by:
I am trying to create a base class that contains a collection that MUST be
able to be referenced by both a string key and a positional index. This
collection MUST keep the items in the same order...
|
by: BSamp |
last post by:
I have the following business entity classes shown below. I have a data
layer that
retrieves the data from the database and populates a new instance of
the PendingRecord class then adds it to the...
|
by: Sugandh Jain |
last post by:
Hi,
I am developing using MS Visual Studio .net 2005, c# 2.0.
My query/confusion is as follows:
If I have a collection of a particular type of object.
While moving in the collection using...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |