Summary

  • An operator is a symbol that causes C# to take an action.

  • The assignment operator (=) assigns a value to an object or variable.

  • C# includes four simple arithmetic operators, +, -, *, and /, and numerous variations such as +=, which increments a variable on the left side of the operator by the value on the right side.

  • When you divide integers, C# discards any fractional remainder.

  • The modulus operator (%) returns just the remainder from integer division.

  • C# includes numerous special operators, such as the self-increment (++) and self-decrement (--) operators.

  • To increment a value before assigning it, you use the prefix operator (++x); to increment the value after assigning it, use the postfix operator (x++). The same rule applies to the decrement operator.

  • The relational operators compare two values and return a Boolean. These operators are often used in conditional statements.

  • The conditional operator ( ? : ) is the only ternary operator found in C#. The test condition is found to the left of the question mark; it invokes the expression to the left of the colon if the tested condition evaluates true and the expression to the right of the colon if the tested condition evaluates false.

  • The compiler evaluates operators according to a series of precedence rules, and parentheses have the “highest” precedence.

  • It is good programming practice to use parentheses to make your order of precedence explicit if there may be any ambiguity.

You saw a lot of math in this chapter, which is certainly useful, because your programs will often perform mathematical operations. We also mentioned several times that these operators will be useful in Chapter 5. Chapter 5 deals with branching, the technique by which you enable your program to take different actions depending on the values contained in the variables. Chapter 5 is going to tie together what you’ve learned so far, and enable you to take the next step with your programming skills.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset