我在C#中使用泛型类型,我新使用泛型类型。所以,现在我陷入了一个问题。我有一些类这样的:泛型类型的声明方法
public class MyModel1
{
}
public class MyModel2
{
}
public class BaseClass<T>
{
}
public class ChildClass1 : BaseClass<MyModel1>
{
}
public class ChildClass2 : BaseClass<MyModel2>
{
}
public class AnotherClass
{
//What will be the syntax of declaring this method
//The syntax of the following method is wrong and incomplete.
//It's there just to give an idea about whai i want to do.
public void MyMethod<T>()
where T : BaseClass<..what to write..>
{
}
}
我的问题是什么将是宣布的MyMethod的语法是否正确,如果我想调用的MyMethod这样的:
MyMethod<ChildClass1>();
你的意思'其中T:BaseClass的'?还有方法缺少返回类型或void。 –
Nkosi
编辑并添加返回类型。不,看起来像'T:BaseClass'不是我正在寻找的。 –