我在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'不是我正在尋找的。 –