Introduction

   


The variety of types presented in the previous chapter allows you to create tailor-made formations of types suited to represent the data of your program's problem domain. However, without operators, these structures are like motionless skeletons unable to respond or perform useful tasks. Operators act; they let you create the muscles and the brain of your program. By mastering these fundamental C# elements, you will soon create program bodies that can run and even perform acrobatics.

C# offers access to a broad range of operators. Apart from some operators dedicated for special purposes, we can divide the remaining operators into four main categories arithmetic, relational, logical, and bit-wise.

Arithmetic operators are applied to values of simple numeric types and form the basis for performing arithmetic calculations in C#, of which distance[ts]mass is an example.

Relational operators provide us with the ability to compare values, as in (sum < 100) using the less than (<) relational operator. Relational operators always form Boolean expressions that, per definition, evaluate to either true or false.

Logical operators let us to combine two or more Boolean expressions (any value of type bool). They go hand-in-hand with the relational operators and allow us, through if and loop statements, to control the flow of execution in a program and build "brainy" applications. For that reason, they are discussed along with the relational operators and flow of control in Chapter 8, "Flow of Control Part I: Branching Statements and Related Concepts."

Bit-wise operators allow us to manipulate individual bits of an operand. The discussion of these operators is beyond the scope of this book.

This chapter focuses on the main arithmetic operators and is considered an integral part of the types discussion begun in Chapter 6, "Types Part I: The Simple Types," due to the close relationship between operators and types.

Even though the string and enumerator types are considered derived types, they both play a fundamental role in C#'s type system and, consequently, are included in the latter half of this chapter.


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net