C Sharp Programming/Operators

C# operators and their precedence closely resemble the operators in other languages of the C family.

Similar to C++, classes can overload most operators, defining or redefining the behavior of the operators in contexts where the first argument of that operator is an instance of that class, but doing so is often discouraged for clarity.

Operators can be grouped by their arity as nullary, unary, binary, ternary, n-ary.

Following are the built-in behaviors of C# operators.

Arithmetic
The following arithmetic operators operate on numeric operands (arguments and  in the "expression" below).

Logical
The following logical operators operate on boolean or integral operands, as noted.

Relational
The binary relational operators,  , , ,  , and   are used for relational operations and for type comparisons.

Assignment
The most basic is the operator. Not surprisingly, it assigns the value (or reference) of its second argument to its first argument. As such, the assignment operator is binary, but has an n-ary form.

(More technically, the operator  requires for its first (left) argument an expression to which a value can be assigned (an l-value) and for its second (right) argument an expression that can be evaluated (an r-value). That requirement of an assignable expression to its left and a bound expression to its right is the origin of the terms l-value and r-value.)

The first argument of the assignment operator is typically a variable. When that argument has a value type, the assignment operation changes the argument's underlying value. When the first argument is a reference type, the assignment operation changes the reference, so the first argument typically just refers to a different object, but the object that it originally referenced does not change (except that it may no longer be referenced and may thus be a candidate for garbage collection).

Short-hand Assignment
The short-hand assignment operators shortens the common assignment operation of  into , resulting in less typing and neater syntax.

Pointer manipulation
''NOTE: Most C# developers agree that direct manipulation and use of pointers is not recommended in C#. The language has many built-in classes to allow you to do almost any operation you want. C# was built with memory-management in mind and the creation and use of pointers is greatly disruptive to this end. This speaks to the declaration of pointers and the use of pointer notation, not arrays. In fact, a program may only be compiled in "unsafe mode", if it uses pointers.''

Others
C sharp/Operatori