开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜