开发者

can i have an ordered dictionary by date

开发者 https://www.devze.com 2022-12-08 23:24 出处:网络
i have a dictionary where the key is a date and the value is an object.is there anyway i can ensure that when i loop through this collection its in chronological order always even after adding 开发者_

i have a dictionary where the key is a date and the value is an object. is there anyway i can ensure that when i loop through this collection its in chronological order always even after adding 开发者_如何学Goand deleting items.


You need to use SortedDictionary


You can use LINQ:

foreach(var kvp in dictionary.OrderBy(kvp => kvp.Key)) {
    //Use kvp.Key and kvp.Value
}


You can use SortedList: http://msdn.microsoft.com/en-us/library/ms132319.aspx
or SortedDictionary: http://msdn.microsoft.com/en-us/library/f7fta44c.aspx

0

精彩评论

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