C# - Operators and Expressions

Operators are used to process the data. Expressions are created by combining the operators with variables and constants.

For example:

int number1, number2, sum;
number1 = 10;
number2 = 20;
sum = number1 + number2;

 In the last statement, two variables using the + symbol. The + is a operator also there are many operators in c#.

Some mathematical operators used for mathematical calculations in programming:
Operator Usage
+ Addition
- Subtraction
/ Division
% Percentage
* Multiplication
There are some other frequently used operators, they are the logical operators. They can compare two values and give result in ‘true’ or ‘false’ they are mostly used to make decisions.

Some decision making statements:
Operators Usage Example
== Equal if(x==y)
&& Checks for multiple conditions if(x>y)&&(y>z)
> Greater than if(x>y)
< Less than if(x<y)
|| Checks for multiple conditions if(x<y)||(y<x)
>= Greater than or equal if(x=>y)
<= Less than or equal if(x<=y)
!= Not equal to x != y

:)

1 comments:

Post a Comment