简体   繁体   中英

Sorted collection class in Silverlight 4?

Does anyone know of a sorted collection class in Silverlight 4? SortedSet<T>, SortedList<T>, and SortedDictionary<T> all seem to be missing.

Of course I can use List<T>.Sort(), or the IEnumerable<T>.OrderBy() extension method. But I'd rather not have to do an O(n log n) sort every time an element is added or removed.


Thanks for your help,
Richard

Here you go. You can find a lot of Mono source code for missing framework classes just by searching for the name of the class + ".cs" on Google.

http://www.koders.com/csharp/fid77AAA5D3D43E8EA58F8D9EFE52B8798463A68472.aspx

Sometimes you have to work out some compiler errors first but it should get you on your way.

Unfortunately sorted collections haven't made it into Silverlight (yet?)

You could have a look at The C5 Generic Collection Library , there's quite a lot of useful things in there, but possibly a bit heavyweight to import into your app depending how much you need.

The Silverlight Toolkit also includes an ordered dictionary based on Red-Black trees.

I was looking for something similar to SortedList in .NET (Something that stays sorted, not using LINQ over a dictionary or a collection to do sorting). I wasn't able to find anything so I came up with this solution. It works similar to a dictionary, maintaining a collection of keys and values and keeping both collections sorted by the key.

http://pastebin.com/CiUbe28c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM