码迷,mamicode.com
首页 > 其他好文 > 详细

泛型的简单用法<T>

时间:2014-07-05 16:55:25      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   cti   for   

 1         private void Form1_Load(object sender, EventArgs e)
 2         {
 3             Print<string>("here");
 4             Print<int>(1222);
 5 
 6             GenericCollections<string> gcl = new GenericCollections<string>();
 7             gcl.Add("这是一个字符串的示例");
 8             DisplayResult<string>(gcl);
 9             GenericCollections<string> gcl2 = new GenericCollections<string>();
10             gcl2.Add(true.ToString());
11             DisplayResult<string>(gcl2);
12             Console.ReadLine();
13         }
14 
15         public void Print<T>(T argument)
16         {
17             Console.WriteLine(argument.ToString());
18         }
19 
20         void DisplayResult<T>(GenericCollections<T> gcl)
21         {
22             foreach (T s in gcl)
23             {
24                 Console.WriteLine(s.ToString());
25             }
26         }

 

泛型的简单用法<T>,布布扣,bubuko.com

泛型的简单用法<T>

标签:style   blog   color   os   cti   for   

原文地址:http://www.cnblogs.com/illday/p/3823096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!