# C# Operator List

This handy reference c# operator list shows you the operators in C#, some are which are straightforward and will be used in every single program or module, while others are more complex and you may not ever use.

- Introduction to Programming
- What is C#?
- Your First Console Application in C#
- Introducing Methods and the Main() Function in C#
- Introducing C# Classes and Structs
- C# Data Types, Variables and Casting
- C# Program Flow Control and Entry Points
- Passing Parameters to Methods and Return Values in C#
- C# Access Modifiers and Scope
- C# Interfaces and Classes
- Using Namespaces in C#
- C# Conditional Statements
- Looping and Iteration in C#
- Using Arrays and Lists in C#
- C# Constants and Read-Only Variables
- Error and Exception Handling in C#
- Using Recursion in C#
**C# Operator List**- Class Inheritance in C#
- C# Class and Method Attributes Explained
- C# Class Constructors and Destructors
- C# Generics Variables
- XML Serialization and Deserialization
- C# String Formatting Examples

** Adverts Blocked** This website is supported entirely by advertisements. Please disable AdBlocking software so that I can continue providing free content and services.

Learn More

This article relates to an old version of the .Net Framework. While the contents are still relevant, future versions of the framework may change, or improve upon, the contents of this article.

The most common of the operators are the arithmetic and logic operators. These will be very familiar to you is you know other programming languages, or mathematics.

## Arithmetic

Operator | Action | Example | Result |
---|---|---|---|

+ | Addition | z = 1 + 2 | z = 3 |

- | Subtraction | z = 1 - 2 | z = -1 |

* | Multiplication | z = 2 * 2 | z = 4 |

/ | Division | z = 22 / 7 | z = 3.142857 |

% | Modulus | z = 22 % 7 | z = 1 |

The modulus operator (%) computes the remainder after dividing its first operand by its second. |

## Logic

Operator | Action | Example | Result |
---|---|---|---|

&& | Logical AND | true && false true && true false && false | false true false |

|| | Logical OR | true || false true || true false || false | true true false |

! | Logical NOT | true && !false | true |

## Increment and Decrement

Operator | Action | Example | Result |
---|---|---|---|

++ | Increment | a=1; a++; | a = 2 |

–– | Decrement | a=1; a––; | a = 0; |

## Relational

Operator | Action | Example | Result |
---|---|---|---|

== | Equals | x = 1; x == 1 | true |

!= | NOT Equals | x = 1; x != 1 | false |

< | Less than | x = 1; x < 2; | true |

> | Greater than | x = 1; x > 0; | true |

<= | Less than or equal to | x = 1; x <= 0 | false |

>= | Greater than or equal to | x = 1; x >= 5 | false |

## Assignment

Operator | Action | Example | Result |
---|---|---|---|

= | Assignment | x = 1 | |

+= | Incremental Addition | a=1; a += 3; | a = 4; |

-= | Incremental Decrement | a=1; a -= 3; | a = -2; |

*= | Multiply by | a=2; a *= 4; | a = 8; |

/= | Divide by | a=8; a /= 2; | a = 4; |

%= | Modulus or Remainder | a=8; a %= 3; | a = 2; |

&= | Logical AND | "x &= y" is equivalent to "x = x & y" | |

|= | Logical OR | "x |= y" is equivalent to "x = x | y" | |

<<= | Left Shift | "x <<= y" is equivalent to "x = x << y" | |

>>= | Right Shift | "x >>= y" is equivalent to "x = x >> y" |

## Others

Operator | Action | Example | Result |
---|---|---|---|

& | Logical AND | if (false & ++i == 1) | false |

| | Logical OR | true | false false | false | true false |

^ | Logical Exclusive XOR | false ^ false false ^ true true ^ true | false true false |

~ | Bitwise Complement | x = ~0x00000000 | x = 0xffffffff |

<< | Left Shift | 1 << 1 | 2 |

>> | Right Shift | -1000 >> 3 | -125 |

?? | Default Value | int y = x ?? -1; | if x = null y = -1 else y = x |

:? | Conditional Operator | condition ? expression if true : expression if false |

Last updated on: Friday 8th September 2017

#### Tim

Your email address will not be published.

Thanks for the handy reference! I saved it to my bookmarks.

-Tim