Hello,
I have a SorterList in C# and I want to return the first element of the list. I tried using the "First" function but it didnt really work.
Can someone please tell me how to do it?
Thanks in advance,
Greg
Hello,
I have a SorterList in C# and I want to return the first element of the list. I tried using the "First" function but it didnt really work.
Can someone please tell me how to do it?
Thanks in advance,
Greg
Use GetByIndex
if (list.Count > 0)
return list.GetByIndex(0);
SortedList listX = new SortedList();
listX.Add("B", "B");
listX.Add("A", "A");
MessageBox.Show(listX.Values(0));
Gordon Bell replied, but in the case you need to get the first key as well.
For the non generic collection:
SortedList tmp2 = new SortedList();
tmp2.Add("temp", true);
tmp2.Add("a", false);
Object mykey = tmp2.GetKey(0);
Object myvalue = tmp2.GetByIndex(0);
For the generic collection:
SortedList<String, Boolean> tmp = new SortedList<String, Boolean>();
tmp.Add("temp", true);
tmp.Add("a", false);
String firstKey = tmp.Keys[0];
bool firstval = tmp[firstKey];