By GokiSoft.com| 15:53 21/09/2021|
C Sharp

[Share Code] Tìm hiểu biến, toán tử, mệnh đề điều kiện, lặp (for, white, do .. while), switch - mảng trong C# - Khoá học lập trình C#



C#
	- Kiến thức căn bản
		- Khai báo biên + Toán tử
		- Mảng + List
		- Mệnh đề điều kiện + Vòng lặp
		- OOP
			- 4 Tích chất trong lập trình OOP -> Core
		- Mô phỏng sự kiện trong C#
	- JSON: Ứng dụng JSON trong dự án.
		XML/JSON
	- CSDL -> Console

C/C++ -> IDE (DevC) -> (coding -> compile) -> exe (binary) -> running (PC)
Java -> IDE (Netbean) -> (Coding -> compile) -> jar (byte code - .class) (tools) -> JVM -> binary -> running (PC)
C# (.NET Framework) -> IDE (Visual Studio) -> (Coding + compile) -> CIL -> binary -> running (PC)

==========================================
Cài đặt môi trường:
	- .NET Framework
	- IDE: Visual Studio

#Java: Class Name -> Student, ClassGroup, ...
#C Sharp: Var, Function -> Viet Hoa Chu Cai Dau Tien
	private (var, function) -> _chu cai thuong...



using System;

namespace Lesson01
{
    class Program
    {
        static void Main(string[] args)
        {
            //TestBasic();
            //Test2();
            //TestLoop();
            TestArray();
        }

        static void TestArray()
        {
            //int -> bool, int -> float, int -> double, int -> char, int -> string
            int[] arr = new int[5];
            //length: arr.length -> 5, index: 0 -> length - 1 (0 -> 4)
            arr[0] = 25;
            arr[1] = 40;
            arr[2] = 64;
            arr[3] = 98;
            arr[4] = 100;
            int[] arr2 = { 25, 40, 64, 98, 100 };
            Console.WriteLine("arr[0] = {0}", arr[0]);
            Console.WriteLine("arr2[0] = {0}", arr2[0]);

            //Nhap du lieu tu ban
            Console.WriteLine("Nhap arr[1] = ");
            arr[1] = int.Parse(Console.ReadLine());

            //Nhap cho ca Array
            for(int i=0;i<arr2.Length;i++)
            {
                Console.WriteLine("Nhap arr2[{0}] = ", i);
                arr2[i] = int.Parse(Console.ReadLine());
            }

            //TEST -> Tinh tong cac phan tu trong mang arr2
            int sum = 0;
            for(int i=0;i<arr2.Length;i++) {
                sum += arr2[i];
            }
            Console.WriteLine("Sum = {0}", sum);

        }

        static void TestLoop()
        {
            int i = 0, j;

            while(i<=5)
            {
                j = 0;
                while(j<=i)
                {
                    Console.Write("*");
                    j++;
                }
                Console.WriteLine("");
                i++;
            }
            Console.WriteLine("===========");
            int rows = 2, columns = 2;
            for(i=0;i<rows;i++)
            {
                for(j=0;j<columns;j++)
                {
                    Console.Write("{0}", i * j);
                }
                Console.WriteLine("");
            }
        }

        static void Test2()
        {
            int choose = 2;

            switch(choose)
            {
                case 1:
                    Console.WriteLine("Hello 1");
                    break;
                case 2:
                case 3:
                    Console.WriteLine("Hello 2-3");
                    break;
                default:
                    Console.WriteLine("Hello 4");
                    break;
            }
        }

        static void TestBasic()
        {
            Console.WriteLine("Hello World!");
            //Khai bao bien
            //Program01.Main01(null);
            int x, y;
            x = 10;
            y = 15;

            int x1 = x++;
            Console.WriteLine("x1 = {0}, x = {1}", x1, x);
            int x2 = ++x;//x = 11 -> 12 -> x2
            Console.WriteLine("x2 = {0}, x = {1}", x2, x);

            x = 2;
            y = 3;
            int x3 = x++ + ++x - y--;
            //x3 = (2)x++(3) + (4)++x(4) - (3)y--(2) = 2 + 4 - 3 = 3
            Console.WriteLine("x3 = {0}, x = {1}, y = {2}", x3, x, y);

            Console.WriteLine("x = " + x + ", y = " + y);
            Console.WriteLine("x = {0} - {0} - {0}, y = {1}", x, y);
            bool isLive = true;
            char c = 'A';
            Console.WriteLine("isLive = {0}, c = {1}", isLive, c);
            string s1 = "Sinh vien Aptech"; //Cach nay dc su dung
            Console.WriteLine("s1 = {0}", s1);
            String s2 = "Sinh vien Aptech - 285 Doi Can"; //Can than khi dung.
            Console.WriteLine("s2 = {0}", s2);

            Console.WriteLine("Nhap s1 = ");
            s1 = Console.ReadLine();
            Console.WriteLine("s1 = {0}", s1);
            Console.WriteLine("Nhap x = ");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("x = " + x);
            float t;
            Console.WriteLine("Nhap t = ");
            t = float.Parse(Console.ReadLine());
            t = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("t = {0}", t);
        }
    }

    class Program01
    {
        public static void Main01(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }

    class Program02
    {
        static void Main12(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

namespace Lesson02
{
    class Program
    {
        static void Main01(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }

    class Program01
    {
        static void Main12(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }

    class Program02
    {
        static void Main12(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}





Tags:

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)