共用方式為


編譯器錯誤 CS0411

更新:2007 年 11 月

錯誤訊息

方法 'method' 的型別引數不能從使用方式推斷。請明確指定型別引數。

如果您呼叫泛型方法但未明確提供型別引數,而使編譯器無法推斷要使用的型別引數,便會發生這個錯誤。若要避免這個錯誤,請在角括弧中加入要使用的型別引數。

範例

下列範例會產生 CS0411:

// CS0411.cs
class C
{
    void G<T>()
    {
    }

    public static void Main()
    {
        G();  // CS0411
        // Try this instead:
        // G<int>();
    }
}

其他可能的錯誤情況還包括,當參數為沒有型別資訊的 null 時︰

// CS0411b.cs
class C
{
    public void F<T>(T t) where T : C 
    {
    }

    public static void Main()
    {
        C c = new C();
        c.F(null);  // CS0411
    }
}