doubt in csharp

  • Thread starter Thread starter Baskar RajaSekharan
  • Start date Start date
B

Baskar RajaSekharan

Hi,

I have one doubt in c_sharp. Please let me know is there any
Collection or Dictonery having the Sort facility. I want to sort a list of
Numbers. how to do that? For Example i am going to store some value in
either Hash dictonery or ArrayList... With out writing code is there any
way to Sort?

Note: Array List is not working fine.

Regards,
R.Baskar
 
Baskar RajaSekharan said:
I have one doubt in c_sharp. Please let me know is there any
Collection or Dictonery having the Sort facility. I want to sort a list of
Numbers. how to do that? For Example i am going to store some value in
either Hash dictonery or ArrayList... With out writing code is there any
way to Sort?

Yes: ArrayList.Sort.
Note: Array List is not working fine.

That suggests you're misusing it. Could you give an example?
 
I have one doubt in c_sharp. Please let me know is there any
Collection or Dictonery having the Sort facility. I want to sort a list of
Numbers. how to do that? For Example i am going to store some value in
either Hash dictonery or ArrayList... With out writing code is there any
way to Sort?

Note: Array List is not working fine.

What do you mean it doesn't work fine? What Sort(..) method do you use?
Are you using right IComparer? Are the objects you want to sort IComparable?

regards,
Bogdan
 
Hi,

ArrayList.Sort() should do the trick, now remember that the elements of the
arraylist MUST implement IComparable.

These are the things I would check:
1- that all elements of the list are of the same type.
2- that this type implement IComparable ( you say that they are numbers, if
you mean with this that they are "int" you are ok with this).

if the above is true then it should work fine, otherwise post the code
and/or the error you are getting


Cheers,
 
Sorted collections are: ArrayList (I don't know what you mean by *it is not
working fine* and SortedList if you need dictionary like collection.

HTH
B\rgds
100
 
OR,

in addition to all these other good suggestions, you could use this gem:
SortedList.

It's a hybrid between an arraylist and dictionary object which keeps its
contents ordered so you don't have to explicitly call a sort method.

When items indexing is used, it behaves like an array, otherwise it behaves
like a hash.
regards
 
Back
Top