我爱Aspx >> C#.Net >> c#泛型学习(二)_C#教程53 {
54 if (t is int) { }
55 if (t is LinkedList<int, string>) { }
56 string str = t as string;
57 if (str != null) { }
58 LinkedList<int, string> list = t as LinkedList<int, string>;
59 if (list != null) { }
60 }
61 }
62 #endregion
63
64}
65
2.继承和泛型
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace VS2005Demo2
6{
7 继承和泛型#region 继承和泛型
8 public class BaseClass<T>
9 { }
10 public class SubClass : BaseClass<int>
11 { }
12
13
14 public class SubClass1<R> : BaseClass<R>
15 { }
16 #endregion
17
18 继承约束#region 继承约束
19 public class BaseClass1<T> where T : ISomeInterface
20 { }
21 public class SubClass2<T> : BaseClass1<T> where T : ISomeInterface
22 { }
23
24 //构造函数约束
25 public class BaseClass3<T> where T : new()
26 {
27 public T SomeMethod()
28 {
29 return new T();
30 }
31 }
32 public class SubClass3<T> : BaseClass3<T> where T : new()
33 { }
34
35 #endregion
36
37 虚拟方法#region 虚拟方法
38 public class BaseClass4<T>
39 {
40 public virtual T SomeMethod()
41 {
Ҷƪл˵?
C# 3.0新特性初步研究 Part1:使用..[04-28]
C# 3.0新特性初步研究 Part2:使用..[04-28]
C# 3.0新特性初步研究 Part3:使用..[04-28]
C# 3.0新特性初步研究 Part4:使用..[04-28]
C# 3.0新特性初步研究 Part5:匿名..[04-28]
C# 3.0新特性初步研究 Part6:使用..[04-28]
C# 4.0语言将出现重大改变,带来..[04-28]
Word文档中快速插入分隔线的技巧..[04-28]
C# 2.0 套接字编程实例初探_C#教..[04-28]
DotNet(C#)学习-你学到什么程度..[04-28]
C# 3.0新特性初步研究 Part1:使用..[04-28]
C# 3.0新特性初步研究 Part2:使用..[04-28]
C# 3.0新特性初步研究 Part3:使用..[04-28]
C# 3.0新特性初步研究 Part4:使用..[04-28]
C# 3.0新特性初步研究 Part5:匿名..[04-28]
C# 3.0新特性初步研究 Part6:使用..[04-28]
C# 4.0语言将出现重大改变,带来..[04-28]
Word文档中快速插入分隔线的技巧..[04-28]
C# 2.0 套接字编程实例初探_C#教..[04-28]
DotNet(C#)学习-你学到什么程度..[04-28]