Prev | Current Page 376 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

The result of a pragma directive cannot change the behavior
of the program to contravene anything within the C# language specification, but it
can do anything outside the scope of the specification. If the compiler doesn??™t understand
a particular pragma directive, it can issue a warning but not an error.
That??™s basically everything the specification has to say on the subject. The
Microsoft C# compiler understands two pragma directives: warnings and checksums.
7.5.1 Warning pragmas
Just occasionally, the C# compiler issues warnings that are justifiable but annoying.
The correct response to a compiler warning is almost always to fix it??”the code is rarely
made worse by fixing the warning, and usually it??™s improved.
However, just occasionally there??™s a good reason to ignore a warning??”and that??™s
what warning pragmas are available for. As an example, we??™ll create a private field that
D
Uses
extern alias
directly
Figure 7.3 Part of the Properties
window of Visual Studio 2008,
showing an extern alias of FirstAlias
for the First.dll reference
198 CHAPTER 7 Concluding C# 2: the final features
is never read from or written to. It??™s almost always going to be useless??¦ unless we happen
to know that it will be used by reflection. Listing 7.9 is a complete class demonstrating
this.
public class FieldUsedOnlyByReflection
{
int x;
}
If you try to compile listing 7.


Pages:
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388