15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7operators <strong>and</strong> Casts<br />

WhaT ’ s in This ChaPTer<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Operators in <strong>C#</strong><br />

The idea of equality when dealing with reference <strong>and</strong> value types<br />

Data conversion between primitive data types<br />

Converting value types to reference types using boxing<br />

Converting between reference types by casting<br />

Overloading the st<strong>and</strong>ard operators for custom types<br />

Adding cast operators to custom types<br />

The preceding chapters have covered most of what you need to start writing useful programs using<br />

<strong>C#</strong>. This chapter completes the discussion of the essential language elements <strong>and</strong> illustrates some<br />

powerful aspects of <strong>C#</strong> that allow you to extend the capabilities of the <strong>C#</strong> language.<br />

oPeraTors<br />

Although most of <strong>C#</strong> ’ s operators should be familiar to C <strong>and</strong> C++ developers, this section discusses<br />

the most important operators for the benefi t of new programmers <strong>and</strong> Visual Basic converts, <strong>and</strong><br />

sheds light on some of the changes introduced with <strong>C#</strong>.<br />

<strong>C#</strong> supports the operators listed in the following table:<br />

CaTegory<br />

oPeraTor<br />

Arithmetic + – * / %<br />

Logical & | ^ ~ && || !<br />

String concatenation +<br />

Increment <strong>and</strong> decrement ++ ––<br />

Bit shifting ><br />

Comparison == != < > =<br />

continues<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!