473,491 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SortedList<T> missing GetByIndex method?

SortedList<Tgeneric has most of the methods of the old SortedList
class, but it's missing a few, and one in particular that puzzles me.

Anyone know why it has no GetByIndex method?

It has IndexOfKey(), and IndexOfValue(), so you can ask it for indices
into the list. You just can't do anything with them, because it has no
method that takes an index and gives you back anything, neither an
entry, nor a key, nor a value.

The old SortedList would at least give you back the value given the
index.

So... what's the use of a sorted list if you can't get the n-th entry?

Was this an oversight? Or is it by design? Or am I blind...?

Jul 18 '07 #1
2 6096
On Wed, 18 Jul 2007 16:32:41 -0700, Peter Duniho
<Np*********@nnowslpianmk.comwrote:
SortedList<intlistOfInts;

...
int i = listOfInts.Values[0];
And yes, my declaration of SortedList<is wrong (as is your reference to
the non-existent generic class "SortedList<T>"...it's actually
"SortedList<TKey, TValue>" :p )...one hopes that that does not in any way
impeded your ability to get the general idea of how to index into the
values of the generic sorted list. :)
Jul 18 '07 #2
On Jul 18, 6:38 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Wed, 18 Jul 2007 16:32:41 -0700, Peter Duniho

<NpOeStPe...@nnowslpianmk.comwrote:
SortedList<intlistOfInts;
...
int i = listOfInts.Values[0];

And yes, my declaration of SortedList<is wrong (as is your reference to
the non-existent generic class "SortedList<T>"...it's actually
"SortedList<TKey, TValue>" :p )...one hopes that that does not in any way
impeded your ability to get the general idea of how to index into the
values of the generic sorted list. :)
If you use an integer as the key, you can use this syntax:

SortedList<int, stringlist = new SortedList<int, string>();

....

string s = list[4];

Chris

Jul 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15879
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
0
1332
by: Adam | last post by:
Hi I split aspx for 1. aspx - www 2. vb But i have problem because Statement is not valid in a namespace. I don't know while this don't power becouse befor split wab all OK Please Help Me...
5
5889
by: Brett Romero | last post by:
I'd like to type a SortedList as very generic on class instantiation: SortedList<T, T> _sl; Then in two particular methods of the class that is called first(of which only one or the other is...
1
4696
by: Michael Primeaux | last post by:
Why does the generic SortedList and generic SortedDictionary not define any virtual members? Thanks, Michael
4
5685
by: Dave Booker | last post by:
So did the .NET 2.0 working group just run out of steam before it got to a ReadOnlyDictionary<> wrapper? I am publishing events containing a SortedList<>, and obviously I don't want event...
1
2512
by: Eran | last post by:
Hi, I have a huge data structure, which I previosly stored in a Dictionary<int, MyObj> MyObj is relatively small (2 int, 1 DateTime, 1 bool). The dictionary I am using is quite large...
3
2161
by: Beorne | last post by:
I have to retrieve the first kei I have inserted in a Dictionary<int,intcalled dict. The only method I found is: Dictionary<int,int>.KeyCollection.Enumerator dke = dict.Keys.GetEnumerator();...
3
439
by: Bruce Wood | last post by:
Sorry if this is a repost. My original post appears to have disappeared. Is it just me, or is the generic SortedList<Tmissing a GetByIndex method. The old (non-generic) SortedList has a method...
0
2887
by: Marc Gravell | last post by:
Well, I'd have to wonder why you don't just use Dictionary<,/ SortedList<,/ SortedDictionary<,(and just use .Keys and .Values) But something like below: List<KeyValuePair<DateTime, double>list...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.