禁用和恢复编译器警告
你可以使用 #pragma warning disable
禁用编译器警告并使用 #pragma warning restore
恢复它们:
#pragma warning disable CS0168
// Will not generate the "unused variable" compiler warning since it was disabled
var x = 5;
#pragma warning restore CS0168
// Will generate a compiler warning since the warning was just restored
var y = 8;
允许以逗号分隔的警告号码:
#pragma warning disable CS0168, CS0219
CS
前缀是可选的,甚至可以混合使用(尽管这不是最佳实践):
#pragma warning disable 0168, 0219, CS0414