The Visual Studio compiler issues warnings for various "hidden errors" in its opinion. In some cases, it really misses and the programmer eliminates them. In others, the programmer agrees with the smart machine, but wants to leave the code unchanged. The number of such warnings can grow, and it becomes difficult to notice new ones. Question: "Are there any attributes or other ways to remove the warning from the list that is issued when compiling?"

    1 answer 1

    If these are only warnings, you can turn them off like this. Let the codes of your warnings 1234 and 9876 (you can peep in the message, it looks like “warning CS1234”)

    #pragma warning disable 1234, 9876 // тут ваш код, генерирующий предупреждение #pragma warning restore 1234, 9876 

    Do not forget to add a comment in which you describe why it is in this place that the warning can be ignored: it will help those who will read your code in six months (for example, you yourself).

    • Tell me how to find out the warning codes, in the list of errors only the "description", "file", "string", "column", "project". Search in Google by the description is complicated by the fact that everything is translated into Russian in the studio. - 4per
    • I tried not to specify the code - it works. thank. - 4per
    • @ 3per: Well, he (the code) is indicated in the warning at the very beginning! - VladD
    • Alas, i.stack.imgur.com/xSW7M.png VS 2008 Rus - 4per
    • one
      @ 3per: You are not looking there :) See the compilation log in the Output window. - VladD