编译器警告 CS3024
更新:2007 年 11 月
错误消息
约束类型“type”不符合 CLS。
编译器发出此警告是因为:将不符合 CLS 的类型用作泛型类型约束会导致用某些语言编写的代码无法使用泛型类。
消除此警告
- 对类型约束使用符合 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;
}
}