It looks SortedList is excluded.. What do you think most appropriate out of existing collections? (to keep the same fast access and changes)
Can silverlight Dictionary be pe开发者_JS百科rmanently sorted?
Best regards VLK
I ported both the Wintellect Power Collections and the C5 Generic Collections to Silverlight. I made them available here - http://jaykimble.net/powercollections-and-c5-collections-for-silverlight4.aspx.
I did this mostly because this question peaked my interest. Feel free to use them in any type of project you would like to use them with.
To answer your question: No. The dictionary does not guarantee ordered items by key.
However the List<T>
supports the BinarySearch
method. This can help you acheive similar goals of the SortedList
.
The documentation has a nice example of how that is basically acheived. See:-
List<T>.BinarySearch Method (T)
You might take a look at Wintellect's Power Collections. This library is free under the EPL. I think the OrderedMultiDictionary will do the trick for you. You should be able to compile this under Silverlight. I have not used this for a couple of years but did use this library (and Richter's threading library) for a WPF project.
Edit:
After playing around with this it looks like you will need to do a little work to get the power collections to work in Silverlight.
My workaround for not having silverlight was to create a generic list with a KeyValuePair type and then ordering the list.
List<KeyValuePair<int, string>> sampleList = new List<KeyValuePair<int, string>>();
//Assuming you have a set of objects in an array or list
foreach(var item in items)
{
sampleList.Add(new KeyValuePair<int, string>>(item.ID, item.Description))
}
sampleList = sampleList.OrderBy(data => data.Key).ToList();
The effect is the same as using a sorted list.
精彩评论