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を意味しましたか?メソッドにも戻り値の型またはvoidがありません。 – Nkosi
編集された戻り値の型。そして、いいえ、それは、 'T:BaseClass'が私が探しているものではないように見えます。 –