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

I need to suppress a compiler warning in C #. Now I can do it as follows:

#pragma warning disable 0649 private string _field; #pragma warning restore 0649 

Is there any way to do this as follows?

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

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

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

Thanks!

+7
c # suppress-warnings
source share
2 answers

not

 private string _field = null; 

delete warning also?

+7
source share

Not. You can do this throughout the project using the build flag, but otherwise the field will be just another (small) block.

Of course, you could assign meaning to it somewhere ... it will make him happy; -p (I assume that it is actually assigned a value through reflection or something else?)

+2
source share

All Articles