C# Programming Basic For Begginer (Part 3) (DataTypes)


 ဒီနေ့သင်ခန်းစာမှာတော့ မတူညီတဲ့ DataTypes (7) မျိုးအကြောင်းကို ရှင်းလင်းပေးထားပါတယ်။

Data Type

Integer Data Type

Int Data Type ကိုကိန်းဂဏန်း တန်းဖိုးများ သိမ်းဆည်းရန်အတွက် အသုံးပြုပါတယ်။

Syntax

<DataType> <Variable> = <Value>

 

Syntax Example

Int X1 = 100

Long X2 = 1000

 

Code

using System;

 

class program

{

    static void Main()

    {

        short X1 = 1;

        int X2 = 2;

        long X3 = 3;

 

        Console.WriteLine("Value of X1=" + X1);

        Console.WriteLine("value of X2=" + X2);

        Console.WriteLine("value of X3=" + X3);

 

    }

}

 

Program Output

Value of X1=1

value of X2=2

value of X3=3

 

Float Data Type

Float Data Type သည် Decimal (ဒသမ) တန်ဖိုးများကို  သိမ်းဆည်းရန်အတွက် အသုံးပြုပါတယ်။

Syntax

<DataType> <Variable> = <Value>

 

Syntax Example

Float X1 = 100.0

Double X2 = 1000.0

 

Code

using System;

 

class program

{

    static void Main()

    {

        float X1 = 1.0f;

        double X2 = 2.0;

        decimal X3 = 3.0m;

 

        Console.WriteLine("Value of X1=" + X1);

        Console.WriteLine("value of X2=" + X2);

        Console.WriteLine("value of X3=" + X3);

 

    }

}

 

 

Program Output

Value of X1=1

value of X2=2

value of X3=3.0

 

Character Data Type

Char Data Type သည် Character (စာလုံး) တန်ဖိုးများကို  သိမ်းဆည်းရန်အတွက် အသုံးပြုပါတယ်။unicode စာလုံးတန်ဖိုးတစ်ခုတည်းကို ကိုင်ဆောင်ထားသည်။

Code

using System;

 

class program

{

    static void Main()

    {

        char X1 = 'A';

        char X2 = 'a';

 

        Console.WriteLine("X1:" + X1);

        Console.WriteLine("X2:" + X2);

 

    }

}

 

 

Program Output

X1:A

X2:a

 

Bool Data Type

Bool Data Type သည် True (or) False (အမှား (သို့)အမှန်) ကိုသိမ်းဆည်းရန်အတွက် အသုံးပြုပါတယ်။

Syntax

Bool <Variable> = <Value>

 

Syntax Example

bool X1 = true

bool X2 = false

 

Code

using System;

 

class program

{

    static void Main()

    {

        bool X1 = true;

        bool X2 = false;

 

        Console.WriteLine("X1 :" + X1);

        Console.WriteLine("X2 :" + X2);

 

    }

}

 

 

Program Output

X1 :True

X2 :False

 

Array Data Type

Array Data Type သည် အမျိုးအစားတူတန်ဖိုးများ ၏ အစီအစဥ်များကို ကိုင်ဆောင်ထားသော ဒေတာအမျိုး အစားတစ်ခုဖြစ်သည်။

Syntax

<DataType>[ ] <ArrayName = {<Value> , <Value>}

<DataType>[,] <ArrayName = {{<Value>,<Value>}, {<Value>,<Value>}}

 

Syntax Example

int []S1 = {2, 4, 3, 9}

int [,]S2 = {{2, 4} , {3, 9}}

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        int[] num = {

      1,

      5,

      7,

      2,

      3,

      8,

      4,

      9,

      6,

      0

    };

 

        Console.WriteLine("1st Number : " + num[0]);

        Console.WriteLine("2nd Number : " + num[1]);

        Console.WriteLine("3rd Number : " + num[2]);

        Console.WriteLine("4th Number : " + num[3]);

        Console.WriteLine("5th Number : " + num[4]);

        Console.WriteLine("6th Number : " + num[5]);

        Console.WriteLine("7th Number : " + num[6]);

        Console.WriteLine("8th Number : " + num[7]);

        Console.WriteLine("9th Number : " + num[8]);

        Console.WriteLine("10th Number : " + num[9]);

 

    }

}

 

Program Output

1st Number : 1

2nd Number : 5

3rd Number : 7

4th Number : 2

5th Number : 3

6th Number : 8

7th Number : 4

8th Number : 9

9th Number : 6

10th Number : 0

 

String DataTypes

Staring Data Type သည် အက္ခရာများ၏ Array ဖြစ်သည်။ System.String ဒေတာအမျိုးအစား ကိုစာကြောင်း တစ်ခု ကိုယ်စားပြုရန် အသုံးပြုသည်။

Syntax

string <Variablename> = <Value>

 

Syntax Example

string str = "OnePercent"

 

Code

using System;

 

class Program

{

 

    static void Main()

    {

 

        string X = "Hello World";

 

        Console.WriteLine(X);

 

    }

}

 

Program Output

Hello World

 

Structure DataType

Structure DataType သည် မတူညီသော DataType များ၏ တန်းဖိုးများကိုစုစည်းပြီး သိမ်းဆည်းရန်အတွက် အသုံးပြုပါသည်။

Syntax

struct <StructureName> {

  <DataType> <VariableName>;

  <DataType> <VariableName>;

};

 

Syntax Example

struct Employee {

  string name;

  int id;

  float salary;

};

 

Code

using System;

 

struct Employee

{

    public int id;

    public float salary;

};

 

public class Program

{

 

    public static void Main()

    {

 

        Employee emp1,

        emp2,

        emp3;

 

        emp1.id = 1;

        emp2.id = 2;

        emp3.id = 3;

        emp1.salary = 10000;

        emp2.salary = 5000;

        emp3.salary = 2500;

 

        Console.WriteLine("Employee ID : " + emp1.id);

        Console.WriteLine("Employee Salary : " + emp1.salary);

        Console.WriteLine();

        Console.WriteLine("Employee ID : " + emp2.id);

        Console.WriteLine("Employee Salary : " + emp2.salary);

        Console.WriteLine();

        Console.WriteLine("Employee ID : " + emp3.id);

        Console.WriteLine("Employee Salary : " + emp3.salary);

 

    }

}

 

Program Output

Employee ID : 1

Employee Salary : 10000

 

Employee ID : 2

Employee Salary : 5000

 

Employee ID : 3

Employee Salary : 2500

 

Post a Comment

Previous Post Next Post

Contact Form