摘要: 1定义 l泛型方法是使用类型参数声明的方法。 class Class3 { void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } /*Generate two error 1 找不到类型或命名空间名称“T”(是否缺少 using 指令或程序集引用?) 2 找不到类型或命名空间名称R... 阅读全文
posted @ 2009-09-19 09:49 b0b0 阅读(428) 评论(0) 推荐(0)
摘要: 1. 泛型类可以从具体的、封闭式构造或开放式构造基类继承 class BaseNode { } class BaseNodeGeneric<T> { } // concrete type class NodeConcrete<T> : BaseNode { } //closed constructed type class NodeClosed<T> : Bas... 阅读全文
posted @ 2009-09-19 09:47 b0b0 阅读(1658) 评论(4) 推荐(1)
摘要: 泛型的定义与使用 1. 泛型的定义 2. 泛型类型参数的使用 定义:只有当方法具有它自己的类型参数列表时,才能称其为泛型方法。 1.1 代码 /// <summary> /// T 作为myGeneric类型参数 /// </summary> /// <typeparam name="T"></typeparam> public class m... 阅读全文
posted @ 2009-09-19 09:44 b0b0 阅读(1096) 评论(1) 推荐(2)