C# Programming Basic For Begginer (Part 4) (Operators)

 


ဒီနေ့အတွက်တော့ Operators (6) မျိုးအကြောင်း ရှင်းပြပေးသွားမှာပါ။ 

Arithmetic Operators

Arithmetic Operators ကို သင်္ချာတွက်ချက်မှုများလုပ်ဆောင်ရန်အတွက် အသုံးပြုပါတယ်။

Operator

Operation

Example

+

ကိန်းဂဏန်းပေါင်းလဒ်

5 + 2 = 7

-

ကိန်းဂဏန်းနုတ်လဒ်

5 – 2 = 3

*

ကိန်းဂဏန်းမြှောက်လဒ်

5 * 2 = 15

/

ကိန်းဂဏန်းစားလဒ်

5 / 2 = 2

%

ကိန်းဂဏန်းများ အချိုးချပြီး ကျန်ရလဒ်

5 % 2 = 3

Syntax

<Value> + <Value>

<Value> - <Value>

<Value> * <Value>

<Value> / <Value>

<Value> % <Value>

 

Syntax Example

10 + 10

10 - 10

10 * 10

10 / 10

10 % 10

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        int X = 10;

        int Y = 5;

 

        int sum = X + Y;

        int difference = X - Y;

        int product = X * Y;

        int quotient = X / Y;

        int remainder = X % Y;

 

        Console.WriteLine("Sum of X and Y : " + sum);

        Console.WriteLine("Difference of X and Y : " + difference);

        Console.WriteLine("Product of X and Y : " + product);

        Console.WriteLine("Quotient of X and Y : " + quotient);

        Console.WriteLine("Remainder of X and Y : " + remainder);

 

    }

}

 

Program Output

Sum of X and Y : 15

Difference of X and Y : 5

Product of X and Y : 50

Quotient of X and Y : 2

Remainder of X and Y : 0

 

Increment and Decrement Operators

Increment and Decrement Operators သည် ကိန်းရှင်တန်ဖိုး တစ်ခုကို 1 ဖြင့် အတိုးလျော့ ပြုလုပ်သည်။

Operator

Operation

Example

++

တန်ဖိုး ၁ တိုးခြင်း

11++ = 12

--

တန်ဖိုး ၁လျော့ခြင်း

11-- = 10

 

Syntax

<Value> ++

<Value> --

 

Syntax

10++

10--

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        int X = 5;

        Console.WriteLine("Initial Value of X : " + X);

        X++;

        Console.WriteLine("Value of X after Increment : " + X);

        X--;

        Console.WriteLine("Value of X after Decrement : " + X);

 

    }

}

 

Program Output

Initial Value of X : 5

Value of X after Increment : 6

Value of X after Decrement : 5

 

Assignment Operators

Assignment Operators သည် Variable/Constant တစ်ခုကို တန်းဖိုး တစ်ခုသတ်မှတ်ရန်အတွက် တာဝန်ရှိပါတယ်။

Operator

Example

Explanation

=

abc = b

Abc ၏ တန်ဖိုးသည် အတူတူပင်ဖြစ်သည်။

+=

abc += b

Abc ၏ တန်းဖိုးအသစ်သည် abc+b ဖြစ်သည်။

-=

abc -= b

Abc ၏ တန်းဖိုးအသစ်သည် abc-b ဖြစ်သည်။

*=

abc *= b

Abc ၏ တန်းဖိုးအသစ်သည် abc*b ဖြစ်သည်။

/=

abc /= b

Abc ၏ တန်းဖိုးအသစ်သည် abc/b ဖြစ်သည်

%=

abc %= b

Abc ၏ တန်းဖိုးအသစ်သည် abc%b ဖြစ်သည်။

 

Syntax

<Variable> = <Value>

<Variable> += <Value>

<Variable> -= <Value>

<Variable> *= <Value>

<Variable> /= <Value>

<Variable> %= <Value>

 

Syntax Example

X1 = 10

X2 += 10

X3 -= 10

X4 *= 10

X5 /= 10

X6 %= 10

 

Code

Value of X1 : 5

Value of X1 : 10

Value of X2 : 5

Value of X2 : 0

Value of X3 : 5

Value of X3 : 25

Value of X4 : 5

Value of X4 : 1

Value of X5 : 5

Value of X5 : 0

 

Comparison Operators

Comparison Operators များကို တန်ဖိုး ၂ခု နှိုင်းယှဉ်ရန် အသုံးပြုပါသည်။

Operators

Function

Example

==

ညီမျှသည်

5 == 5

!=

မညီမျှခြင်း

5 != 5

> 

ထက်ကြီးသည်

15 > 5

< 

ထက်နည်းသည်

15 < 5

>=

ထက်ကြီးသည် သို့ ညီမျှသည်

15 >=

<=

ထက်နည်းသည် သို့ ညီမျှသည်။

15 <=

 

Syntax

<Value> == <Value>

<Value> != <Value>

<Value> < <Value>

<Value> > <Value>

<Value> <= <Value>

<Value> >= <Value>

 

Syntax Example

10 == 10

10 != 10

10 > 10

10 < 10

10 >= 10

10 <= 10

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        int X = 5;

        int Y = 5;

 

        Console.WriteLine("X is Equal to Y : " + (X == Y));

        Console.WriteLine("X is not Equal to Y : " + (X != Y));

        Console.WriteLine("X is more than Y : " + (X > Y));

        Console.WriteLine("X is less than Y : " + (X < Y));

        Console.WriteLine("X is more than or equal to Y : " + (X >= Y));

        Console.WriteLine("X is less than or equal to Y : " + (X <= Y));

 

    }

}

 

Program Output

X is Equal to Y : True

X is not Equal to Y : False

X is more than Y : False

X is less than Y : False

X is more than or equal to Y : True

X is less than or equal to Y : True

 

Logical Operators

Logical Operators သည် အခြေနေများစွာကို ပေါင်းစပ်ရန် အသုံးပြုပါသည်။

Operator

Meaning

Example

Output

&&

ဖော်ပြချက် ၂ခုလုံးဖြစ်ပါက ၁ကိုပြန်ပေးသည်။

5 == && 10 == 0

0

||

အနည်းဆုံးဖော်ပြချက် ၁ ပါလျှင် ၁ကိုပြန်ပေးသည်။

5 == 5 || 10 == 0

1

!

ရလဒ်ကို ၁ မှ ၀ သို့ ပြန်ပေးသည်။

5 == 5

0

 

Syntax

<Condition> && <Condition>

<Condition> || <Condition>

!<Condition>

 

Syntax Example

X==Y && X!=Y

X>Y || X<Y

!X

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        int X = 5;

        int Y = 10;

 

        Console.WriteLine("First Condition : " + (X == Y && X != Y));

        Console.WriteLine("Second Condition : " + (X < Y || X > Y));

        Console.WriteLine("Third Condition : " + !(X == Y));

 

    }

}

 

Program Output

First Condition : False

Second Condition : True

Third Condition : True

 

Bitwise Operators

Bitwise Operators များကို Binary အဆင့်ရှိတန်ဖိုးများကို နှိုင်းယှဉ်ရန် အသုံးပြုပါသည်။

Operators

Meaning

and

Bitwise AND

or

Bitwise OR

xor

Bitwise XOR

inv()

Bitwise NOT

shl

Bitwise Left Shift

shr

Bitwise Right Shift

 

Syntax

<Value> & <Value>

<Value> | <Value>

<Value> ^ <Value>

~ <Value>

<Value> <<

<Value> >>

 

Syntax Example

10 & 10

10 | 10

10 ^ 10

~10

10 <<

10 >>

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        int X = 25;   // 0001 1001

        int Y = 75;   // 0100 1011

 

        Console.WriteLine("Bitwise AND : " + (X & Y));

        Console.WriteLine("Bitwise OR : " + (X | Y));

        Console.WriteLine("Bitwise XOR : " + (X ^ Y));

        Console.WriteLine("Bitwise NOT : " + (~X));

        Console.WriteLine("Bitwise LEFT SSHIFT : " + (X << 1));

        Console.WriteLine("Bitwise RIGHT SHIFT : " + (X >> 1));

 

    }

}

 

Program Output

Bitwise AND : 9

Bitwise OR : 91

Bitwise XOR : 82

Bitwise NOT : -26

Bitwise LEFT SSHIFT : 50

Bitwise RIGHT SHIFT : 12

 

 

Post a Comment

Previous Post Next Post

Contact Form