这里
https://en.wikipedia.org/wiki/Generic_programming
文档公共描述先回答你的两个问题:
- 在.NET中所有类型,泛型类型和其他人
Object
派生。
- 泛型类型可能与任何其他类型一样是抽象的,但它不需要。如果你创建一个抽象泛型类型,你需要从它派生一个非抽象类型,以便能够从中实例化一个对象。
要确定类型是否是泛型,只需查看类定义即可。 Queue
不是通用类型,而Queue<T>
是通用类型,因为通过用其他类型替换通用类型参数T
可以获得不同的类型。例如Queue<int>
,Queue<string>
,Queue<Object>
等全部使用与Queue<T>
类中定义的代码相同的代码。注意它们本身也是泛型类型。嵌套在泛型中的嵌套类型也被认为是泛型类型。 “基本类型”Queue<T>
被称为泛型类型定义。
public abstract class MyListBase { }
public abstract class MyListBase<T> : MyListBase { }
public class MyList<T> : MyListBase<T>
{
public class Nested { }
}
public class MyStringList : MyList<string> { }
...
var isGenericType0 = typeof(MyListBase).IsGenericType; //False
var isGenericType1 = typeof(MyListBase<>).IsGenericType; //True
var isGenericType2 = typeof(MyListBase<>)
.MakeGenericType(typeof(char)).IsGenericType; //True
var myIntegerList = new MyList<int>();
var isGenericType3 = myIntegerList.GetType().IsGenericType; //True
var myNested1 = new MyList<int>.Nested();
var isGenericType4 = myNested1.GetType().IsGenericType; //True
var myStringList = new MyStringList();
var isGenericType5 = myStringList.GetType().IsGenericType; //False
希望你可以用你的头周围泛型类型现在。
我建议你从https://msdn.microsoft.com/en-us/library/512aeb7t.aspx开始 –
从Object派生的所有.net类型。作为其他参考类型的泛型类型可以是或不可以根据程序员决定抽象 – Ivan
感谢Jon Skeet,我正在研究它。谢谢伊凡 - 在这方面抽象是无关紧要的? –