你的位置:首页 > 软件开发 > ASP.net > using System.Collections.Generic;

using System.Collections.Generic;

发布时间:2016-09-24 23:00:10
类型参数使得设计类和方法时,不必确定一个或多个具体参数,其的具体参数可延迟到客户代码中声明、实现。  这意味着使用泛型的类型参数T,写一个类MyList<T>,客户代码可以这样调用:MyList<int>, MyList<string>或 My ...

  类型参数使得设计类和方法时,不必确定一个或多个具体参数,其的具体参数可延迟到客户代码中声明、实现。

  这意味着使用泛型的类型参数T,写一个类MyList<T>,客户代码可以这样调用:MyList<int>, MyList<get='_blank'>string>或 MyList<MyClass>。

  这避免了运行时类型转换或装箱操作的代价和风险。

下面是普通的方法调用:

 1     public static void ShowInt(int iValue) 2     { 5       Console.WriteLine(" ShowInt方法 展示{0},其类型为{1}", iValue, typeof(int));//,iValue.GetType()); 6     } 7  8     public static void ShowLong(long lValue) 9     {10       Console.WriteLine(" ShowLong方法 展示{0},其类型为{1}", lValue, lValue.GetType());11     }12 13     public static void ShowString(string sValue)14     {15       Console.WriteLine(" ShowString方法 展示{0},其类型为{1}", sValue, sValue.GetType());16     }17 18     public static void ShowDateTime(DateTime dValue)19     {20       Console.WriteLine(" ShowDateTime方法 展示{0},其类型为{1}", dValue, dValue.GetType());21     }

原标题:using System.Collections.Generic;

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录