四 28th, 09
随意摘
遍历 Dictionary<TKey, TValue> 型的集合机会不多 —— 遍历字典集合本身就是一个很糟糕的主意。不过却也因此忽略了一些东西,不废话,见代码。
1: // 适用 foreach 遍历 Dictionary 集合中的元素时,
2: // 元素的正确类型应该是 KeyValuePair<TKey, TValue>.
3: Console.WriteLine();
4: foreach( KeyValuePair<string, string> kvp in openWith )
5: {
6: Console.WriteLine("Key = {0}, Value = {1}",
7: kvp.Key, kvp.Value);
8: }
参数工厂实现起来很丑陋
1: // 声明, 想想看,我需要多少个 if, typ [...]