Ad Code

Responsive Advertisement

C# Operators and arithmetic operations

C# Operators and arithmetic operationsOperators: They are special symbols that are used in programming languages to perform specific work such as arithmetic, logic, comparison, reference, and other important operations. C# is one of the most transaction-rich programming languages, which is divided into several main categories:


  • Relational Operators.
  • Arithmetic Operators.
  • Logical operators.
  • Bitwise Operators.
  • Assignment Operators.

C# Operators and arithmetic operations



Comparison operators in C# Relational Operators


( == ) Equal To


It is used to compare two values ​​and if the values ​​are equal then true is returned.


(!=) Not Equal To


This parameter is used to compare two unequal values. If the values ​​are not equal, it returns true, and if the values ​​are equal, it returns false.


(<) Greater than


This parameter is used to compare two values ​​and if the first value is greater than the second then it returns true.


(>) Less Than


This parameter is used to perform a comparison if the first value is less than the second value and if so it returns a value (true).


(<= ) Greater Than Equal To


This parameter is used to check if the first value is greater than or equal to the second, and if so, it returns true.


(>=) Less Than Equal To


Used to check if the first value is less than or equal to the second, and if so, it returns true.


Arithmetic Operators in C# Arithmetic Operators


These operators are used to perform various arithmetic and mathematical operations. The following is a list of these operands:


(+) Addition


This operator is used to add two or more numbers.


(-) Subtraction


It is used to subtract the second number from the first number.


(*) Multiplication


It is used to multiply numbers.


(/) Division


It is used to perform the division operation.


(% ) Modulus


It is used to calculate the remainder of the division.


(++) Increment


Used to increment by one over an integer.


(–) Decrement


Used to decrement an integer value by one.


Logical operators in C# Logical Operators


Logical AND conditional operator “and”


This parameter is used as is used in the regular and, where it requires the fulfillment of both conditions in order to obtain the bug of the value (true) and its result is different depending on the case in which it is used:


True && True = True

True && false = false 

False && True = False 

False && False = False


Logical OR “||” "or"


When using this parameter “||” A true result is given if one of the conditions is met or both conditions are met, and the result is as follows:


True || True = True

True || false = True 

False || True = True

False || False = False


Bitwise Operators in C Bitwise Operators


In C#, there are bit-level operators that are used to perform special operations and are executed as follows:


C# Operators and arithmetic operations


Assignment Operators in C#



It is used to assign a specific value. Example: (x=y+b)


=+


It adds the value to the left of the parameter to the value on the right and then assigns it to the value on the left. Example:  (C+=A is exactly the same as C=C+A).


=-

Subtracts the value to the left of the parameter from the value on the right and assigns it to the value on the left. Example: (C - = A equals C = C - A).


=*


Multiplies the value to the left of the parameter by the value on the right and then assigns it to the value on the left. Example: (C*=A equals C = C* A).


=/


Divide the value to the left of the operand by the value to the right of the operand, then assign it to the value on the left. Example: (C / = A is equal to C = C / A).


=%


It is used to calculate the remainder of the division of the value to the left of the operand to the value to the right of the operand, and then assign it to the value on the left. Example: (C%=A is equal to C=C%A).