四 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, typeof 判断?
2: public class Factory {
3: public static IMath Init<T>() {
4: if( typeof( T ) is int ) {
5: return new IntImplIMath();
6: }
7: }
8: }
9:
10: // 调用
11: ops.Math = Factory.Init<int>();
都说 Oxite 写的恶心, 今天算是见识到了
快速链接:http://www.antigamez.com/go/45809.html
相关日志
本文地址 : http://www.antigamez.com/articles/%e9%9a%8f%e6%84%8f%e6%91%98.html
如果你对本文感兴趣,欢迎订阅我的博客
Leave a Reply