简体   繁体   English

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

[英]in C# can we do something like this List<? of CustomType>

I have a custom type, which is abstract. 我有一个自定义类型,它是抽象的。 and will have some class to extend the abstract class. 并将有一些类来扩展抽象类。

somewhere i need to deal with a list of object which are the children my custom abstract type. 某处我需要处理一个对象列表,这些对象是我自定义抽象类型的子对象。

i am wonder in C#, can i do somthing like this: 我在C#中很奇怪,我能做这样的事吗:

void Method(List<? is CustomType> objs)
{
}

thx 谢谢

void Method<T>(List<T> objs)
    where T : CustomType
{
}

i think what you are looking for is a generic method. 我认为你在寻找的是一种通用的方法。 Those are definitely supported: 这些肯定是支持的:

void Method<T>(List<T> objs) where T: CustomType
{
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们可以像C#一样在jQuery中进行文件处理吗? - Can we do file handing in jQuery like C#? 有没有办法在C#中做这样的事情? - Is there any way to do something like this in C#? 在XSL中,执行类似C#的操作:list.Select(x =&gt; x.ID).Distinct(); - In XSL, do something like in C# : list.Select(x=>x.ID).Distinct(); 我可以在 c# 中做类似 foreachwhile 循环的事情吗(这就是我将如何引用它)? - can I do something like a foreachwhile loop(that's how I will be refering to it) in c#? C#可以在Java(Meta-inf / service)中做类似SPI的事情吗? - Can C# do something like SPI in Java (Meta-inf/service)? c#我可以为“if”这样做吗? 或任何其他方式做这样的事情? - c# Can I do this for “if”? or any other way to doing something like this? 使用Oracle类型(如CustomType表)从C#调用存储过程 - Calling Stored procedures from C# with Oracle type like Table of CustomType C#是否执行Windows窗体的动态继承之类的操作? - C# Do something like dynamic inheritance for Windows Forms? 如何做“类 <? extends MyClass > “在C#中 - How to do something like “Class<? extends MyClass >” in C# 如何在mootools中传递对象本身(就像我们在C#中可以做的那样)? - How to I pass the object itself (like how we can do in C#) in mootools?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM