My question is like the following question but with SortedList<Tkey, TValue>
instead of just the original SortedList
.
Return first element in SortedList in C#
There doesn't seem to be a function like GetKey()
.
You can simply use list.FirstOrDefault()
and list.LastOrDefault()
.
These two methods will return default(KeyValuePair<TKey,TValue>)
if the list is empty.
And it's better to use them because using list.First()
and list.Last()
will throw error in case the list was empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With