Type unboundGenericList = typeof(List<>);
Type listOfInt = unboundGenericList.MakeGenericType(typeof(int));
if (listOfInt == typeof(List<int>))
Console.WriteLine("Constructed a List<int> type.");
public class Basket<T> {
T[] basketItems;
}
public class PicnicBlanket<T> {
Basket<T> picnicBasket; // Open type here. We don't know what T is.
}
// Closed type here: T is Food.
public class ParkPicnicBlanket : PicnicBlanket<Food> {
}
在这里,picnicBasket的类型是打开的: 还没有分配给 T的任何东西。当您使用特定类型(例如,通过编写 PicnicBlanket<Food> p = new PicnicBlanket<Food>())创建具体的 PicnicBlanket 时,我们现在将其称为 关门了。