調べてみると、stackoverflow にあった。
How to add 2 Dictionary contents without looping in c#
http://stackoverflow.com/questions/712927/how-to-add-2-dictionary-contents-without-looping-in-c-sharp
サンプルはそのままだけど書いてみた。
class Program {
static void Main(string[] args) {
Dictionary dict = new Dictionary();
dict.Add(0, "test");
Dictionary addDict = new Dictionary();
addDict.Add(2, "foo");
addDict = addDict.Concat(dict).ToDictionary(x => x.Key, x => x.Value);
Console.WriteLine("Data Count = {0}", addDict.Count);
foreach(int key in addDict.Keys) {
Console.WriteLine("{0} : {1}", key, addDict[key]);
}
Console.ReadKey();
}
} // class End...
上手く動いている。
0 件のコメント:
コメントを投稿