C# #pragma 警告禁用和恢复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15715170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#pragma warning disable & restore
提问by SaravanaKumar
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.)
我使用 c# 创建了第一个项目。我有很多警告错误,所有这些警告错误都是单个错误(内部编译器错误。有关更多信息,请参阅控制台日志。)
For Reducing the warning errors I used #pragma Warning disable . #pragma warning restore front and back of the problematic code.
为了减少警告错误,我使用了 #pragma Warning disable 。#pragma warning 恢复有问题代码的前后。
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 警告禁用和恢复,因为它在程序中;还是我需要删除它?例如:
#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?
对于最终构建,我是否需要删除它?
回答by Alexei Levenkov
If it is code of any practical value you should not have any warning and compile with "warnings as error" setting with all warnings turned on.
如果它是具有任何实用价值的代码,则不应有任何警告并使用“警告为错误”设置进行编译并打开所有警告。
Code you showing does not seem like it have any errors in itself. So I see no reasons why you need the pragma.
您显示的代码本身似乎没有任何错误。所以我看不出你需要 pragma 的理由。
But it is really your call - your code and if no one need to use/look/pay for it - do whatever works for you.
但这真的是你的决定——你的代码,如果没有人需要使用/查看/付费——做任何对你有用的事情。
回答by Deleted
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:
您可以从 Visual Studio 的构建输出窗口中获取与您决定忽略的构建问题相关的警告编号。它们通常被标记为“警告 CS0168....”或类似标签。在这种情况下,您可以专门针对您决定忽略的那些错误,如下所示:
#pragma warning disable 168, 3021
//Your code that generates warnings CS0168 and CS3021 here
#pragma warning restore 168, 3021
回答by Ajay2707
I got this error in my asp.net mvc (.net core) application. Based on this above and other article show this error comes from your c sharp code in chtml side.
我在我的 asp.net mvc (.net core) 应用程序中遇到了这个错误。基于以上和其他文章显示此错误来自您在 chtml 端的 c 尖锐代码。
To identify the issue, just open console or open cshtml in separate window.
要确定问题,只需打开控制台或在单独的窗口中打开 cshtml。
I have a popup where this error comes, I separately open this popup and while investing error in console, I got that one semi-colon not in cshtml, so while rendering chtml it throw the error.
我有一个出现此错误的弹出窗口,我单独打开此弹出窗口,在控制台中投资错误时,我得到了一个不在 cshtml 中的分号,因此在呈现 chtml 时它会抛出错误。