共用方式為


編譯器警告 CS3024

更新:2007 年 11 月

錯誤訊息

條件約束型別 'type' 不符合 CLS 標準。

因為使用非 CLS 標準型別做為泛型型別條件約束 (Constraint),會讓以某些語言撰寫的程式碼無法使用您的泛型類別 (Class),所以編譯器 (Compiler) 會發出這個警告。

若要去除這個警告

  • 針對型別條件約束,使用符合 CLS 標準的型別。

範例

下列範例會在數個位置產生 CS3024:

// cs3024.cs
// Compile with: /target:library
 [assembly: System.CLSCompliant(true)]

[type: System.CLSCompliant(false)]
public class TestClass // CS3024
{
    public ushort us;
}
[type: System.CLSCompliant(false)]
public interface ITest // CS3024
{}
public interface I<T> where T : TestClass
{}
public class TestClass_2<T> where T : ITest
{}
public class TestClass_3<T> : I<T> where T : TestClass
{}
public class TestClass_4<T> : TestClass_2<T> where T : ITest
{}
public class Test
{
    public static int Main()
    {
        return 0;
    }
}

請參閱

參考

型別參數的條件約束 (C# 程式設計手冊)