以前一直模模糊糊的知道泛型,模模糊糊的使用着泛型,但是就是没有一个比较深入的了解

今天比较空闲 自己写了一个小类  终于有点明白了

 

 

泛型类
1 using System;
2  using System.Collections.Generic;
3  using System.Linq;
4 using System.Web;
5
6 /// <summary>
7 ///fx 的摘要说明
8 /// </summary>
9 public class fx<Str,Int,Date> : Dictionary<Str,fx1<Int,Date>>
10 {
11 public fx()
12 {
13 //
14 //TODO: 在此处添加构造函数逻辑
15 //
16 }
17
18
19
20 public void Add(Str str, Int I, Date Dt)
21 {
22 base.Add(str,new fx1<Int, Date>(I,Dt));
23 }
24
25 public void Remove(Str str)
26 {
27 base.Remove(str);
28 }
29
30 public string Get(Str str)
31 {
32 fx1<Int,Date> fx = base[str];
33 return fx.I.ToString() + "," + fx.Dt.ToString();
34 }
35
36
37
38
39 }
40
41 public class fx1<Int,Date>
42 {
43 public fx1(Int i,Date dt)
44 {
45 I = i;
46 Dt = dt;
47 }
48 public Int I { set; get; }
49 public Date Dt { set; get; }
50 }
51

前台调用代码

1 fx<int, string, DateTime> fx = new fx<int, string, DateTime>();
2 fx.Add(1, "100", DateTime.Now);
3 fx.Add(2,"200", DateTime.Now);
4 Response.Write(fx.Get(2));
posted on 2010-08-24 17:01  skyzhou  阅读(305)  评论(4编辑  收藏  举报