c sharp operators

C sharp have large  set of operators  we can define operator as "The symbols which defines which operation is performed in the expression ".
For Example:

                  int x = 2;
                 int y = 3;

               int sum = x + y;  
 // this an expression and the Operator ( + ) shows that the numerical values i.e will be added then will be assigned to  sum . 
    Console.WriteLine(sum);
   
 
     }
    }
}
   C# have the following  commonly used Operators.

Assignment Operators:
  
the Assignment Operators are used to assign Values to Variables in C sharp . 

for example :

if  int x =10  ; its mean that   we have a variable of Integer type and   x have  value which is assigned to x through assignment Operator (=).

Combined Assignment Operators in C sharp:

In C sharp like most other Languages we  can have combined assignment Operators  by combining the Ar-thematic operators and assignment operators.
For example :
we can have combined assignment operators as  int x +=2; which means that  int x =x+2; Some of other combined assignment Operators are as follow.

  •  *=   for example : int x =x*2;
  • /=   for example : int x= x/2;
  • %=   for example : int x = x % 2;
  • +=   for example : int x = x +2 ; 
Equality Operators:
the Equality Operators in C sharp make one variables value equal or not equal to other one.
int  x =2 ;  int y ;
if (x==1)
{
   //   you are equal to one 
and if the value is not equal to 1 then as follow 
if(x!=1)
{
   
   // do this you are not equal to one 
}

Logical AND  and Logical OR Operators:

 Logical AND and Logical OR Operators Evaluates Two Variables and then execute the program according to given conditions. 
Logical AND Operators are Represents by (&&) signs . Can be used in Program as follow.
















In the above program  the 2 variables namely x and y have their own values  in our condition we use logical AND operators which means that the x must be equal to 2 and y must be equal to 2 . its will evaluates the both conditions  must be return True.

Its the main Difference in Logical AND and Logical OR operators  in logical AND Operator the both conditions must be return True . if any one of them is not True then the  if statement will not executes. And will simply jumps to else Condition.  But in OR  Logical Condition Only 1 condition out of them should return True. as in following Program.


 













Now if we look at the above program we can see that y value is = 29  and in our logical condition. Is to print on Screen x =2 and y=3 if x==2  or y=2 meaning that any should be equal to 2 and the first x =2 so  it will print  x =2 and y=3 .

No comments:

Post a Comment

Sending SMS Via Windows Form Application Using any Android Smart Phone  Source Code  using System ; using System . C...