Disabling and Restoring Compiler Warnings C# with Example



Disabling and Restoring Compiler Warnings C# with Example

You can disable compiler warnings using #pragma warning disable and restore them using #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; 
Comma-separated warning numbers are allowed: 
#pragma warning disable CS0168, CS0219 
The CS prefix is optional, and can even be intermixed (though this is not a best practice): 
#pragma warning disable 0168, 0219, CS0414 

0 Comment's

Comment Form

Submit Comment