代码检查:对于具有非可空类型种类的类型参数,其基类型约束上的可空注解是多余的。
当其他约束如 class、 struct、 unmanaged 或 notnull 已使类型参数为非可空类型时,此检查会报告类型约束上的可空注解。 在这种情况下,约束上的 ? 是自相矛盾且无效的。
#nullable enable
using System;
class C
{
void M<T>() where T : notnull, IDisposable?
{
}
}
#nullable enable
using System;
class C
{
void M<T>() where T : notnull, IDisposable
{
}
}
根据约束列表,也可以通过其他快速修复来移除冗余的非可空类型种类约束。
2026年 5月 8日