C# Operators


This entry is part 4 of 4 in the series C# Primitives and Expressions

What is an operator in C#? An operator is a program element that is applied to one or more operands in an expression or statement.

This C# statement contains a single unary operator and a single operand. The increment operator, ++, modifies the value of the operand y. So operators work on operands.

  • y++;

In the above example, we have previously declared a variable called y. We have given it a type, perhaps integer. We have also previously initialized it to a value, probably zero. The increment operator (++) is used here to increase the value of y by one.

Types of Operators

There are different types of operators: mathematical, assignment and logical. Operators can also be classified into three types: unary, binary and ternary. What is our example of y++? The urnary mathematical operator ++ is operating on an operand y, which is a variable. The result is an statement.

Mathematical Operators

There are five simple mathematical operators, two of which (+ and -) have both binary and unary forms.

Operator precedence.

PRECEDENCE OPERATORS
Highest ++, −− (used as prefixes); (), +, – (unary), !, ˜
*, /, %
+, –
<<, >>
<, >, <=, >=
==, !=
&
^
|
&&
||
=, *=, /=, %=, +=, −=, <<=, >>=, &=, ^=, |=
Lowest ++, –– (used as suffixes)
Series Navigation<< C# Type Conversion

Leave a Reply