Is it possible to disable specific compiler warnings?

做~自己de王妃 提交于 2019-12-05 11:36:52

To suppress specific warnings for Visual C# or F#:

  1. In Solution Explorer, choose the project in which you want to suppress warnings.
  2. On the menu bar, choose View, Property Pages.
  3. Choose the Build page.
  4. In the Suppress warnings box, specify the error codes of the warnings that you want to suppress, separated by semicolons, and then rebuild the solution.

Check out here for more info on how to suppress specific warning for Visual C++ and Visual Basic.


Another ways is to use #pragma warning can enable or disable certain warnings.:

#pragma warning disable warning-list
#pragma warning restore warning-list

warning-list

A comma-separated list of warning numbers. Enter the numbers alone, without the "CS" prefix. When no warning numbers are specified, disable disables all warnings and restore enables all warnings.

Yes, it is possible.

#pragma warning disable 'warning-number-list'

where warning-number-list is a comma separated list of warning numbers to disable, e.g. 1004

This will disable the warning from its point of declaration to the end of the current file unless re-enable with:

#pragma warning restore 'warning-number-list'.

These pragmas are placed inline in your code at the site of where you wish to disable/restore the warnings.

I believe there is also a place on the Project properties tabs to specify warnings to disable, as you mentioned.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!