IMPORTANT PLEASE READ!
Website development and design blog, tutorials and inspiration

C# Operator List

Handy C# Operator list for reference

By , Written on in C#

C# Operator List

280 words, estimated reading time 2 minutes.

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.
 
C# Programming Series
  1. Introduction to Programming
  2. What is C#?
  3. Your First Console Application in C#
  4. Introducing Methods and the Main() Function in C#
  5. Introducing C# Classes and Structs
  6. C# Data Types, Variables and Casting
  7. C# Program Flow Control and Entry Points
  8. Passing Parameters to Methods and Return Values in C#
  9. C# Access Modifiers and Scope
  10. C# Interfaces and Classes
  11. Using Namespaces in C#
  12. C# Conditional Statements
  13. Looping and Iteration in C#
  14. Using Arrays and Lists in C#
  15. C# Constants and Read-Only Variables
  16. Error and Exception Handling in C#
  17. Using Recursion in C#
  18. C# Operator List
  19. Class Inheritance in C#
  20. C# Class and Method Attributes Explained
  21. C# Class Constructors and Destructors
  22. C# Generics Variables
  23. XML Serialization and Deserialization
  24. C# String Formatting Examples

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

OperatorActionExampleResult
+Additionz = 1 + 2z = 3
-Subtractionz = 1 - 2z = -1
*Multiplicationz = 2 * 2z = 4
/Divisionz = 22 / 7z = 3.142857
%Modulusz = 22 % 7z = 1
The modulus operator (%) computes the remainder after dividing its first operand by its second.

 

Logic

OperatorActionExampleResult
&& Logical ANDtrue && false
true && true
false && false
false
true
false
||Logical ORtrue || false
true || true
false || false
true
true
false
!Logical NOTtrue && !falsetrue

 

Increment and Decrement

OperatorActionExampleResult
++Incrementa=1;
a++;
a = 2
––Decrementa=1;
a––;
a = 0;

 

Relational

OperatorActionExampleResult
==Equalsx = 1;
x == 1
true
!=NOT Equalsx = 1;
x != 1
false
<Less thanx = 1;
x < 2;
true
>Greater thanx = 1;
x > 0;
true
<=Less than or equal tox = 1;
x <= 0
false
>=Greater than or equal tox = 1;
x >= 5
false

 

Assignment

OperatorActionExampleResult
=Assignmentx = 1
+=Incremental Additiona=1;
a += 3;
a = 4;
-=Incremental Decrementa=1;
a -= 3;
a = -2;
*=Multiply bya=2;
a *= 4;
a = 8;
/=Divide bya=8;
a /= 2;
a = 4;
%=Modulus or Remaindera=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


OperatorActionExampleResult
&Logical ANDif (false & ++i == 1)false
|Logical OR true | false
false | false
true
false
^Logical Exclusive XORfalse ^ false
false ^ true
true ^ true
false
true
false
~Bitwise Complement x = ~0x00000000x = 0xffffffff
<<Left Shift1 << 12
>>Right Shift-1000 >> 3-125
??Default Valueint y = x ?? -1;if x = null y = -1 else y = x
:?Conditional Operatorcondition ? expression if true : expression if  false

Last updated on: Friday 8th September 2017

Did you Like this Post? Why not Like us on Facebook?

 

Comments
  1. Tim
    Tim

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

Leave a Reply

Your email address will not be published.