csharp-collections

msdn

Dictionary

//Dictionary<TKey,TValue>
Dictionary<string,Model_driver> cur_driver = new Dictionary<string, Model_driver>();
if (cur_driver.ContainsKey(it.Name))
{
...
}

SortedDictionary<TKey, TValue>

// Create a new dictionary of strings, with string keys.
//
Dictionary<string, string> openWith =
new Dictionary<string, string>();

// If a key does not exist, setting the indexer for that key
// adds a new key/value pair.
openWith["doc"] = "winword.exe";

// Add some elements to the dictionary. There are no
// duplicate keys, but some of the values are duplicates.
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe");

// The indexer can be used to change the value associated
// with a key.
openWith["rtf"] = "winword.exe";

// ContainsKey can be used to test keys before inserting
// them.
if (!openWith.ContainsKey("ht"))
{
openWith.Add("ht", "hypertrm.exe");
Console.WriteLine("Value added for key = \"ht\": {0}",
openWith["ht"]);
}

List

public ObservableCollection<Model_data> List_userData();

List_userData.ToList();
List<Model_data> list = null;
list = new List<Model_data>(App.db.List_userData());

ObservableCollection<int> myCollection = new ObservableCollection<int>(myList);

排序

list = list.OrderBy(o => o.Id).ToList();//升序
list = list.OrderByDescending(o => o.Id).ToList();//降序

// 多权重排序
list = list.OrderBy(o => o.Id).ThenBy(o=>o.Name).ToList();
list = list.OrderByDescending(o => o.Id).ThenByDescending(o=>o.Name).ToList();//降序

Queue

ObservableCollection

// 删除
foreach (var item in itemSet)
{
if (item.ItemID == itemToCompareTo.ItemID)
{
itemSet.Remove(item);
// 这里必须break 否则会抛异常
break;
}
}