15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

58 ❘ ChaPTer 2 cOre c#<br />

directive can be used to restore the match. You can also use the syntax #line default to restore the line to<br />

the default line numbering:<br />

#line 164 "Core.cs" // We happen to know this is line 164 in the file<br />

// Core.cs, before the intermediate<br />

// package mangles it.<br />

// later on<br />

#line default<br />

// restores default line numbering<br />

#pragma<br />

The #pragma directive can either suppress or restore specific compiler warnings. Unlike comm<strong>and</strong>-line<br />

options, the #pragma directive can be implemented on a class or method level, allowing fine-grained<br />

control of what warnings are suppressed <strong>and</strong> when. The following example disables the “field not used”<br />

warning <strong>and</strong> then restores it after the MyClass class compiles:<br />

#pragma warning disable 169<br />

public class MyClass<br />

{<br />

int neverUsedField;<br />

}<br />

#pragma warning restore 169<br />

<strong>C#</strong> Programming guidelines<br />

The final section of this chapter supplies the guidelines you need to bear in mind when writing <strong>C#</strong><br />

programs.<br />

rules for identifiers<br />

This section examines the rules governing what names you can use for variables, classes, methods, <strong>and</strong><br />

so on. Note that the rules presented in this section are not merely guidelines: they are enforced by the <strong>C#</strong><br />

compiler.<br />

Identifiers are the names you give to variables, to user-defined types such as classes <strong>and</strong> structs, <strong>and</strong> to<br />

members of these types. Identifiers are case-sensitive, so, for example, variables named interestRate <strong>and</strong><br />

InterestRate would be recognized as different variables. Following are a few rules determining what<br />

identifiers you can use in <strong>C#</strong>:<br />

➤<br />

➤<br />

They must begin with a letter or underscore, although they can contain numeric characters.<br />

You can’t use <strong>C#</strong> keywords as identifiers.<br />

The following table lists the <strong>C#</strong> reserved keywords.<br />

abstract event new struct<br />

as explicit null switch<br />

base extern object this<br />

bool false operator throw<br />

break finally out true<br />

byte fixed override try<br />

case float params typeof<br />

catch for private uint<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!