9, you??™ll get a warning message like this:
FieldUsedOnlyByReflection.cs(3,9): warning CS0169:
The private field 'FieldUsedOnlyByReflection.x' is never used
That??™s the output from the command-line compiler. In the Error List window of Visual
Studio, you can see the same information (plus the project it??™s in) except that you don??™t
get the warning number (CS0169). To find out the number, you need to either select
the warning and bring up the help related to it, or look in the Output window, where
the full text is shown. We need the number in order to make the code compile without
warnings, as shown in listing 7.10.
public class FieldUsedOnlyByReflection
{
#pragma warning disable 0169
int x;
#pragma warning restore 0169
}
Listing 7.10 is self-explanatory??”the first pragma disables the particular warning we??™re
interested in, and the second one restores it. It??™s good practice to disable warnings for
as short a space as you can, so that you don??™t miss any warnings you genuinely ought to
fix. If you want to disable or restore multiple warnings in a single line, just use a
comma-separated list of warning numbers. If you don??™t specify any warning numbers
at all, the result is to disable or restore all warnings in one fell swoop??”but that??™s a bad
idea in almost every imaginable scenario.
7.5.2 Checksum pragmas
You??™re very unlikely to need the second form of pragma recognized by the Microsoft
compiler.
Pages:
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389