Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

Viewed 24770

Is there a way to suppress warnings in C# similar to Java's @SuppressWarnings annotation?

Failing that, is there another way to suppress warnings in Visual Studio?

8 Answers

You can use the SuppressMessage data annotation which will prevent the warning.

It looks something like this:

[SuppressMessage("Reason #Enter whatever you'd like", "ID, must match what intellsense is showing it looks something like this: IDE0001", Justification = "(optional, your own description")]

Here is a real world example:

[SuppressMessage("IntelliSenseCorrection", "IDE0001", Justification = "Do Not Remove <T> Variable, It's Required For Dapper")]
Related