Example #1
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // vi du ve chuoi va mang 1 chieu
            string chuoi = "Hello World";
            int[] arr = new int[5] { 1, 2, 3, 4, 5 };
            Console.WriteLine("Gia tri cua chuoi la {0}", chuoi);
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write("{0} ", arr[i], " ");               
            }
            Console.WriteLine();
            // vi du ve tinh chap oop
            // tinh bao đóng           
            var tiger1 = new Tiger(50, "White Tiger");
            tiger1.Display();
            var tiger2 = new Tiger();
            // Ở trường hợp này ta sẽ k thể set giá trị Name và Height cho Tiger2 do các thuộc tính của Tiger đã để private
            // tính kế thừa
            var cat1 = new Cat();
            cat1.Name = "Tom";
            cat1.Height = 10;
            cat1.Move();
            cat1.Say();
            // tính đa hình: từ class cha Animal có nhiều loại class con extend như Cat, Dog, ...
            var dog1 = new Dog(15, "Beg");
            dog1.Display();
            // tính trừu tượng
            var squa = new Square();
            squa.Display();
            Console.ReadKey();
        }
    }
}