随意摘

遍历 <TKey, TValue> 型的集合机会不多 —— 遍历字典集合本身就是一个很糟糕的主意。不过却也因此忽略了一些东西,不废话,见代码。

   1: // 适用  遍历  集合中的元素时,

   2: // 元素的正确类型应该是 <TKey, TValue>.

   3: Console.WriteLine();

   4: ( <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>();

都说 写的恶心, 今天算是见识到了


Rand Posts:

相关日志

本文地址 : http://www.antigamez.com/articles/%e9%9a%8f%e6%84%8f%e6%91%98.html
如果你对本文感兴趣,欢迎订阅我的博客

Leave a Reply