Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SortedList in C# have no Find method?

Silly if you ask me. But this message is here because I will assume (probably correctly) that I am the silly one, not Microsoft. So... is there something I'm missing? Why didn't they include a "Find" method to this baby? The find could work on the Values, which are objects, so then I could do this:

someObject = SortedList.Values.Find(order => order.OrderID == orderID);
like image 680
Axonn Avatar asked Oct 27 '25 07:10

Axonn


1 Answers

You might be looking for .First(...) or .Single(...) (or their OrDefault variants) in LINQ, but that only really works well with types that implement IEnumerable<T>. A SortedList is not strongly typed, hence the Lambda won't work. Have a look at LINQ's .Cast<T>().

like image 103
Daniel A. White Avatar answered Oct 28 '25 22:10

Daniel A. White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!