代码检查:在受非空基类型约束的类型参数的 'class?' 约束上冗余的可空注解。
当其他基类型约束已经保证类型参数为非空时,此检查会报告在引用类型约束上的可空注解。 在这种情况下, ? 在 class 约束上是冗余或矛盾的。
#nullable enable
using System;
class C
{
void M<T>() where T : class?, IDisposable
{
}
}
#nullable enable
using System;
class C
{
void M<T>() where T : class, IDisposable
{
}
}
另一个快速修复是在更符合预期泛型约定时,将约束类型注解为可空。
2026年 5月 8日