C# Programming Basic For Begginer (Part 2)

 


ဒီအပိုင်းမှာတော့  C# ရဲ့  Cocepts တွေကို  ရှင်းပြပေးထားပါတယ်။ လိုအပ်ချက်တွေ အမှားတွေရှိခဲ့ရင်လဲ Telegram မှာ ဆွေးနွေးနိုင်ပါတယ်။ 

Basic Cocepts in C#

Comment

Introduction to comments

Programming တွင် comment သည် Programer ဖတ်နိုင်သော ရှင်းလင်းချက် သို့မဟုတ် source code ရဲ့မှတ်ချက် တစ်ခုဖြစ်ပါတယ်။ comments များကို compiler များမှ လျစ်လျူရှုထားပါတယ်။ comment code ထားရှိခြင်းသည် သင့်အ တွက်ရော အခြားသူအတွက်ပါ ရှင်းလင်းပြီး နားလည်ရလွယ်ကူသောကြောင့် comment များထားခြင်းသည် အလေ့ကျင့် ကောင်းတစ်ခုဖြစ်ပါတယ်။

Syntax

 // <Comment>

/*<comment> */

 

Syntax Example

 // Single Line comment

/* MultLine comment */

 

Code

using System.IO;

using System;

 

class Program {

 

  static void Main() {

 

    // This is a Single Line Comment

    /* This is a

      Multi Line Comment */

 

  }

}

Program Output

 

 

Output ရှင်းလင်းချက်

Compiler မှ comment ကို လျစ်လျူရှုထားသောကြောင့်  Output မှာ ဘာမှမရှိတာပါ။

DataType

Introduction to DataType

          DataType သည် Memory အတွင်းရှိ data အမျိုးအစားများကို သတ်မှတ်ပေးသည့် attribute တစ်ခုဖြစ်ပါတယ်။ program တစ်ခုရဲ့ အခြေခံလိုအပ်ချက်မှာ data သိမ်းဆည်းရန်ဖြစ်ပါတယ်။ မတူညီတဲ့ Memory ပမာဏကို ယူဆောင်ကာ သိမ်းဆည်းရန် မတူညီတဲ့ data အမျိုးအစားများ ရှိပါတယ်။ data အမျိုးအစားအားလုံးတွင် လုပ်ဆောင်မှု အားလုံးကို လုပ်ဆောင်မရပါ။ data type တစ်ခုစီတိုင်းမှာ လုပ်ဆောင်သည့် လုပ်ဆောင်ချက်များသည် ကွဲပြားပါတယ်။ ဒါကြောင့် data မသိမ်းဆည်းမှီ Memory တွင် သိမ်းဆည်းမည့် data အမျိုးအစားကို ဖော်ပြပါ။

DataType are classified into

Ø  Value DataType

Ø  Reference DataType

Ø  Pointer DataType

DataType

Memory

Range

boolean

1 Byte

0 and 1

signed char

1 Byte

-128 to 127

unsigned char

1 Byte

0 to 127

signed char

2 Byte

=32,768 to 32,767

unsigned short

2 Byte

0 to 65,535

signed int

4 Byte

-2,147,483,648 to 2,147,483,647

unsigned int

4 Byte

O to 4,294,967,295

signed long

8 Byte

9,223,372,036,8 54,775,808 to 9,

unsigned long

8 Byte

0 to 18,446,744,0 73,709,551,615

float

4 Byte

1.5*10-45 to 3.4 1038

double

8 Byte

5.0 10-324 to 1.7 * 10308

decimal

16 Byte

-7.9* 10?28 to 7.9 * 1028

 

DataType

Description

Arrays

Array is a collection of Homogenous Data

String

A string is an object that represents

 

DataType

Description

Pointers

Pointer points to a value's memory

 

Identifiers

Introduction to Identifiers

          Identifier သည် Program တစ်ခုရှိ element အတွက် သတ်မှတ်ထားသော Assigned name ဖြစ်ပါတယ်။ identifier များသည် Memory တွင် သိမ်းဆည်းထားသည့် Data များကို သီးသန့်ခွဲခြားသတ်မှတ်ရန် အသုံးပြုသူ သတ်မှတ် ထားသော အမည်များဖြစ်ပါတယ်။ identifier သည် နံပါတ်တစ်ခုဖြင့် စတင်မရပါ။ identifier တွင် အမှတ်အသား (_)မှလွဲပြီး အထူးစာလုံးများ မပါဝင်ပါ။ identifier တွင်နေရာလွတ်များမရှိပါ။ identifierသည် အဓိကစကားလုံးမဖြစ်နိုင်ပါ။

Code

using System.IO;

using System;

 

class Program

{

 

    static void Main()

    {

 

        // Declaring and Initializing Constant

        const int con1 = 5;

        const int con2 = 12;

 

        // Declaring and Initializing Variable

        int var1 = 5;

        int var2 = 12;

 

        // Changing Variable Name

        var1 = 10;

        var2 = 20;

 

        // Print Values

        Console.WriteLine("First Constant = " + con1);

        Console.WriteLine("Second Constant " + con2);

        Console.WriteLine("First Varaiable = " + var1);

      Console.WriteLine("Second Varaiable " + var2);

 

    }

}

 

Program Output

First Constant = 5

Second Constant 12

First Varaiable = 10

Second Varaiable 20

 

Output Explanation

            2 constants နှင့် int Data Type ရဲ့  Variable 2ခုကို ကြေငြာပေးထားပါတယ်။ ကိန်းသေများကို အစပြုထားပြီး တန်းဖိုးများကို ပြောင်းလဲမရပါ။ Variable များကို အစပြုထားပါတယ်။ သူတို့ရဲ့ တန်ဘိုးပြောင်းလဲသွားတယ်။  Print statement သည် Value ကို print ထုပ်လိုက်တာပါ။

 

Constants

Introduction to Constants

          Constants ဆိုတာ Data သိမ်းဆည်းထားသည့်နေရာဟု အမည်ပေးထားတဲ့ မှတ်ဉာဏ်တည်နေရာတစ်ခု ဖြစ်ပါတယ်။ Constants သည်တူညီသည့် Name တွေမရပါဘူး။ Program ကို execution လုပ်နေစဉ်မှာ Constants ၏  Value တွေမပြောင်နိုင်ပါဘူး။ Constants name တွေကို Upper Case Letter ဖြင့်သာ စတင်သင့်ပါသည်။

Invalid Declaration

Valid Declaration

Reason

const int 5a

const int a5

ကိန်းသေအမည်ဖြင့် စတင်လို့မရပါ။

const char !x

const char _x

ကိန်းသေအမည်ဖြင့် စတင်လို့မရပါ။

const double pie value

const double pie_value

WhatSpace မရနိုင်ပါ။

const bool if

const bool whatif

Constant Name တစ်ခုမဖြစ်နိုင်ပါ။

 

Code

using System.IO;

using System;

 

class Program

{

 

    static void Main()

    {

 

        // Declaring and Initializing Constant

        const int con1 = 5;

        const int con2 = 12;

 

        // Print Values

        Console.WriteLine("First Constant = " + con1);

        Console.WriteLine("Second Constant = " + con2);

 

    }

}

 

Program Output

First Constant = 5

Second Constant = 12

 

Variables

Introduction to Variables

          Variables ဆိုတာ Data သိမ်းဆည်းထားသည့်နေရာဟု အမည်ပေးထားတဲ့ မှတ်ဉာဏ်တည်နေရာတစ်ခု ဖြစ်ပါတယ်။ Variables သည်တူညီသည့် Name တွေမရပါဘူး။ Program ကို execution လုပ်နေစဉ်မှာ Variables ၏  Value ကိုပြောင်းလဲနိုင်သည်။

Invalid Declaration

Valid Declaration

Reason

int 5a

int a5

နံပါတ်ဖြင့် အစပြုလို့မရပါ။

char !x

char _x

Variables Name ဖြင့် စတင်လို့မရပါ။

double pie value

double pie_value

Variables Name မရနိုင်ပါ။

bool if

bool whatif

Variables Name တစ်ခုမဖြစ်ရပါ။

 

Code

using System.IO;

using System;

 

class Program

{

 

    static void Main()

    {

 

        // Declaring and Initializing Constant

        int var1 = 5;

        int var2 = 12;

 

        // Changing Values

        var1 = 10;

        var2 = 20;

 

        // Print Values

        Console.WriteLine("First Constant = " + var1);

        Console.WriteLine("Second Constant = " + var2);

 

    }

}

 

Program Output

First Constant = 10

Second Constant = 20

 

Literals

          Literals သည် ပုံသေတစ်ခုကို ကိုယ်စားပြုရန်အတွက် Notation Value တစ်ခုဖြစ်ပါသည်။ ရိုးရိုးရှင်းရှင်း ပြောရရင် အဓိပ္ပါယ်ဖွင့်ဖို့ ရေးထားတဲ့ Value တစ်ခုပါ။ Variable သည် မတူညီသောတန်ဖိုးများကိုကိုယ်စားပြုပြီး ကိန်းသေတစ်ခုသည် တူညီသောတန်ဖိုးကိုကိုယ်စားပြုသည်။ Literal သည် Value ကိုယ်တိုင်ဖြစ်သည်။

ဥပမာ - company = “OnePercent”

OnePercent သည် Literals ၏ တန်ဖိုးပါ။

Keyworlds

Introduction to Keyworlds

          Keyworlds သည် programming တွင်အသုံးပြုသော compiler အတွက် အထူးအဓိပ္ပါယ်ရှိသော ကြိုတင်သတ်မှတ် ထားသည့် သီးသန့်စကားလုံးများဖြစ်သည်။ Keyworlds သည် Syntax ရဲ့အစိတ်အပိုင်းဖြစ်ပြီး identifier အဖြစ်အသုံးပြုလို့ မရနိင်ပါ။ အောက်မှာဖော်ပြထားသော ဇယားမှာ C# ရဲ့  Keyworlds တွေပါ။ နောက်သင်ခန်းစာတွေမှာ Keyworlds အားလုံးကို လေ့လာသွားပါမည်။

 

abstract

as

base

break

byte

case

char

checked

class

continue

decimal

default

do

double

else

event

explicit

extern

finally

fixed

float

foreach

goto

if

i

int

null

operator

out

overrie

private

protected

public

ref

return

sbyte

short

sizeof

stackalloc

struct

switch

this

true

try

typeof

ulong

unchecked

unsage

using

virtual

void

while

.

.

 

Tokens

Introduction to Tokens

          Tokens သည် C# program တွင် compiler အတွက်အဓိပ္ပါယ်ရှိသော အသေးငယ်ဆုံး ယူနစ်ဖြစ်သည်။ Tokens ကိုအမျိုးအစား ၆မျိုးခွဲခြားထားပါတယ်။

Token

Example

Keyworlds

If, int

identifiers

Int Quanity, Price

Operators

,

 

Operators

Introduction to Operators

          Operators သည် Value (သို့) Variable တစ်ခုပေါ်တွင် လုပ်ဆောင်သည့် သင်္ကေတဖြစ်သည်။ ဥပမာ - <#>+ သည်နံပါတ်များထည့်ရန် Operators တစ်ခုဖြစ်ပါတယ်။ Operators အမျိုအစားတွေကို အောက်တွင် ဖော်ပြပေးထားပါတယ်။

·       Arithmetic Operators

·       Increment/Decrement Operators

·       Comparison Operators

·       Logical Operators

·       Assignment Operators

·       Bitwise Operators

Access Specifiers

Introduction to Access Specifiers

          Access Specifiers ကို determining (သို့) class အပြင်ဘက်ရှိ class member များ၏ နယ်နမိတ်ကို သတ်မှတ်ပါတယ်။ Data Hiding အကောင်ထည်ဖော်ရန် Access Specifiers များသည် အရေးကြီးပါသည်။ ၎င်းသည် OOPS Concepts ၏ အရေးကြီးသော အစိတ်အပိုင်း တစ်ခုဖြစ်သည်။ နောက်ပိုင်းသင်ခန်းစာတွေမှာ OPPS  သင်ခန်းစာ Tutorial များကိုလေ့လာသွားပါမည်။

Ø  PUBLIC :

Ø  PRIVATE :

Ø  PROTECTED :

Ø  INTERNAL :

Ø  PROTECTED INTERNAL :

Input and Output

Console.WriteLine()

          Console.WriteLine() method သည် Screen တွင် Output ထုပ်ပေးသည့် Format ဖြစ်ပါတယ်။ မည်သည့်စာသား မဆို  “”  အတွင်းရိုက်ပြီး ပြသနိုင်ပါတယ်။ {} အတွင်း အညွှန်း သတ်မှတ်ထားသည့် နေရာဖြစ်ပါတယ်။  ပြီးရင်တော့ print ထုပ်လိုက်တဲ့ value ရဲ့ indentifier ကိုသတ်မှတ်ပေးလိုက်ပါ။  သင်သည် များစွာသော တန်ဖိုးများကို သတ်မှတ်နိုင်ပြီး ၎င်းကို {} အတွင်းသတ်မှတ်ထားသော index တွေကို အစီအစဉ်အတိုင်းရိုက်နှိပ်နိုင်ပါတယ်။ ပြီးနောက် data ကို {} နေရာတွင် ရိုက်နှိပ် နိုင်ပါတယ်။   

 

Console.ReadLine()

          Console.ReadLine()သည် အသုံးပြုသူထံမှ ထည့်သွင်းမှုကို လက်ခံရန် နည်းလမ်းတစ်ခု ဖြစ်သည်။ Console.ReadLine() သည် အသုံးပြုသူမှထည့်သွင်းထားသောတန်ဖိုးကို ပြန်ပေးမည်ဖြစ်ပြီး ၎င်းတန်ဖိုးကို နောက်ပိုင်းအသုံး ပြုရန်အတွက် Variable တွင် သိမ်းဆည်းထားသည်။

 

Syntax

Console.WriteLine(<YOUR_TEXT>);

<Variable> = Console.ReadLine();

 

 Syntax Example

Console.WriteLine("Enter Your Name : ");

string Name = Console.ReadLine();

 

Code

// C# program to illustrate

// the use of Console.ReadLine()

// to pause the console

using System;

using System.IO;

 

class Smiple

{

 

    // Main Method

    public static void Main()

    {

        string name;

        int n;

 

        Console.WriteLine("Enter your name: ");

 

        // typecasting not needed as

        // ReadLine returns string

        name = Console.ReadLine();

 

        Console.WriteLine("Hello " + name +

            " Welcome to iFix it Center!");

 

        // Pauses the console until

        // the user presses enter key

        Console.ReadLine();

    }

}

 

Output

Enter your name:

aung myint oo

Hello aung myint oo Welcome to iFix it Center!

 

Control Statements

Introduction to Control Statements     

Ø  Control Statements သည် မည်သည့်ထုတ်ပြန်ချက်ကို အကောင်အထည်ဖော်ရန် ဆုံးဖြတ်ရန် တာဝန်ရှိသည်။  (if Statements )

Ø  ကြေငြာချက်တစ်ခုအား လုပ်ဆောင်ရမည့်အကြိမ်အရေအတွက်ကိုလည်း ဆုံးဖြတ်သည်။ (Loop)

Ø  SELECTION - စကားရပ်တစ်ခု၏ အခြေအနေကို စစ်ဆေးပြီး အခြားအရာများကို ကျော်သွားသည့် သီးခြား ကုဒ်တစ်ခု ကိုသာ လုပ်ဆောင်သည်။

Ø  ITERATION- စကားရပ်တစ်ခု၏ အခြေအနေကို စစ်ဆေးပြီး စကားရပ် မှားသွားသည်အထိ ကုဒ်တစ်ခုကို ထပ်ခါ ထပ်ခါ လုပ်ဆောင်သည်။

 

Ø  If

 

Ø  If Else

 

Ø  Else If Ladder

 

Ø  Nested If

 

Ø  Switch Case

 

Ø  While Loop

 

Ø  Do-While Loop

 

Ø  For Loop

 

Ø  Nested Loop

Post a Comment

Previous Post Next Post

Contact Form