Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

c# - #pragma warning disable & restore

I have used c# to create a First Project. I have many warning errors and all these warning errors are to be single Error(Internal compiler error. See the console log for more information.)

For Reducing the warning errors I used #pragma Warning disable . #pragma warning restore front and back of the problematic code.

I have doubt that in my final build I should leave that #pragma warning disable & restore as it is in the program; or do I need to remove that? e.g:

#pragma warning disable
if (Displayer.instance != null && CTR.Tore== "Keepit")
{
    Displayer.instance.SetFielderProfile (i);
}
#pragma warning restore

For final build do I need to remove that or not?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At the very least you should be specific about which warnings you've deliberately chosen to ignore. That way, if later maintenance introduces a 'new' warning/issue that you should be made aware of, the warning about the newly-introduced error won't be suppressed by your blanket pragma warning disable directive.

You can get the warning numbers pertaining to the build issues you've decided to ignore from the build Output window in Visual Studio. They're usually labelled "Warning CS0168...." or similar. In which case you can specifically target just the those error(s) you've decided to ignore like so:

#pragma warning disable 168, 3021

    //Your code that generates warnings CS0168 and CS3021 here

#pragma warning restore 168, 3021

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...