An operator is a symbol (such as =, +
, or >
) that causes C# to take an action. That action might be an assignment of a value to a variable, the addition of two values, a comparison of two values, and so forth. In that respect, most C# operators aren’t much different from the ones you remember from math class, and they’re intended to be just that intuitive. There are some special operators whose meanings aren’t obvious, and we’ll cover those, too.
In the preceding chapter, you were introduced to the assignment operator. The single equals sign (=
) is used to assign a value to a variable; in this case, the value 15 to the variable myVariable
:
myVariable = 15;
C# has many different operators that you’ll learn about in this chapter. There’s a full set of mathematical operators, and a related set of operators just for incrementing and decrementing in integral values by one, which actually are quite useful for controlling loops, as you’ll learn in Chapter 5. Operators are also available for comparing two values that are used in the branching statements, as we’ll also demonstrate in Chapter 5.
Get Learning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.