By GokiSoft.com| 16:01 02/10/2021|
C Sharp

[Video] Hướng dẫn tìm hiểu biến + toán tử trong lập trình C#

[Video] Hướng dẫn tìm hiểu biến + toán tử trong lập trình C#



#Program.cs


using System;

namespace Lession2
{
    class Program
    {
        static void Main(string[] args)
        {
            //TimHieuToanTu();
            //MenhDeDieuKien();
            //MenhDeDieuKien2();
            SwitchCase();
        }

        static void SwitchCase() {
            int day = 1;
            switch(day) {
                case 1:
                    Console.WriteLine("test 1");
                    break;
                case 2:
                    Console.WriteLine("test 2");
                    break;
                default:
                    Console.WriteLine("Other");
                    break;
            }
        }

        static void MenhDeDieuKien2() {
            int num = 13;
            if(num < 0) {
                Console.WriteLine("The number is negative");
            } else {
                Console.WriteLine("The number is positive");
                if(num % 2 == 0) {
                    Console.WriteLine("The number is even");
                } else {
                    Console.WriteLine("The number is odd");
                }
            }

            if(num < 0) {
                Console.WriteLine("The number is negative");
            } else if(num % 2 == 0) {
                Console.WriteLine("The number is even");
            } else {
                Console.WriteLine("The number is odd");
            }
        }

        static void MenhDeDieuKien() {
            int num = 10;
            if(num < 0) {
                Console.WriteLine("The number is negative");
            } else {
                Console.WriteLine("The number is positive");
            }
            Console.WriteLine("Stop");
        }

        static void TimHieuToanTu() {
            //const float PI = 3.14f;
            int x = 5;
            int y = x++;//y = 5, x = 6
            int t = ++x;//x = 7, t = 7
            Console.WriteLine("x = {0}, y = {1}, t = {2}", x, y, t);
            //x = 7, y = 5, t = 6

            int z = x++ + ++x - --y + t++ + 1;
            //z = 7(x=8) + (x=9)9 - (y=4)4 + 7(t=8) + 1
            //z = 20
            Console.WriteLine("x = {0}, y = {1}, t = {2}, z = {3}", x, y, t, z);

            int k = 10;
            string str = (k != 10) ? "K khac 10" : "K bang 10";
            Console.WriteLine(str);
        }
    }
}


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

5

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