禁用和恢復編譯器警告
你可以使用 #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