1

これまで、C# の推論は常にうまく機能していました。ケースを単純化するために、テスト例を作成しました。

class Parent
{
    public void InferrenceTesting<T>() where T : Parent
    {

    }
}

class Child : Parent
{
    public void Test()
    {
        //this line gives me a compiler error : The type arguments for method 'Parent.InferrenceTesting<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
        this.InferrenceTesting();
    }
}

私は推論についてかなり読んだことがありますが、なぜこれが機能しないのかはわかりません。

4

4 に答える 4

2

型を推測するために使用できるものは何もありません。Tの型である必要があると言いましたParentが、その型のパラメーターを渡していないため (コンパイラーが型を推測するために使用できます)、型に明示的に名前を付ける必要があります。

于 2016-04-13T15:58:39.890 に答える