在C#中我们可以做这样的List <?CustomType>

joj*_*ojo 2 c# .net-4.0

我有一个自定义类型,它是抽象的.并将有一些类来扩展抽象类.

某处我需要处理一个对象列表,这些对象是我自定义抽象类型的子对象.

我在C#中很奇怪,我能做这样的事吗:

void Method(List<? is CustomType> objs)
{
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Mar*_*tos 6

void Method<T>(List<T> objs)
    where T : CustomType
{
}
Run Code Online (Sandbox Code Playgroud)


Gar*_*y.S 5

我认为你在寻找的是一种通用的方法.这些肯定是支持的:

void Method<T>(List<T> objs) where T: CustomType
{
}
Run Code Online (Sandbox Code Playgroud)

关于泛型的MSDN:http://msdn.microsoft.com/en-us/library/ms379564( v = vs.80).aspx