Search code examples
c#.netsuppress-warnings

How to suppress a compiler warning in C# without using #pragma?


I need to suppress a specfic compiler warning in C#. Now I can do it like this:

#pragma warning disable 0649

private string _field;

#pragma warning restore 0649

Is there a way to do it like the following?

[SuppressCompilerWarning("0649")]
private string _field;

Because I only need to suppress warnings for this field, not a code block.

Note: I want to suppress the compiler warning, not the Code-Analysis warning.

Thanks!


Solution

  • Doesn't:

    private string _field = null;
    

    remove the warning as well?