返回
Featured image of post C♯ - 自訂類型(Custom types) - 類別(Class) 筆記

C♯ - 自訂類型(Custom types) - 類別(Class) 筆記

類別(Class) 筆記

官方基本範例

    class Child
    {
        private int age;
        private string name;

        // Default constructor:
        public Child()
        {
            name = "N/A";
        }

        // Constructor:
        public Child(string name, int age)
        {
            this.name = name;
            this.age = age;
        }

        // Printing method:
        public void PrintChild()
        {
            Console.WriteLine("{0}, {1} years old.", name, age);
        }
    }
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus