Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • Are you talking about System.Collections.Generic.SortedList<TKey, TValue>? Commented Jul 8, 2013 at 13:54
  • It's actually more efficient to add the items to a List and then sort it than to add the items to a SortedList. SortedList is, in most cases, inferior to another collection for any particular task. I've almost never found it to be the best collection for any given job. Commented Jul 8, 2013 at 14:03
  • @Henrik: yeas, I missed the first generic argument. Thanks Commented Jul 8, 2013 at 14:13
  • @Servy: does it matter? The idea of my answer was to highlight the creation of a custom object. The SortedList is completary to simplify the sorting requirement. Maybe there are faster collections, lower memory consumption collections, etc. But as there is no "realtime" or heavy requirement mentioned, I can live with that. Feel free to add extra link for more advanced users. Commented Jul 8, 2013 at 14:17
  • @SteveB Well, that and SortedList doesn't have a constructor that accepts delegates, so this code won't even work. The point was you went out of your way to change the code the OP was using (which was a list that he called Sort on) to a SortedList. Just leaving the code that he had, and using a List, would be better in quite a number of ways, including, among other things, performance. Commented Jul 8, 2013 at 14:22