個人學習筆記:

理解 Class 和 Method 的差異,我想有助於對C#的了解,

 

在一個Dos畫面的範例內,

開頭的 using System ,是載入一個 System的 library .

 

Console.WriteLine() 這行 ,

Console是一個class ,

WriteLine()是它底下的一個 method

 

 

 

用一個自建的class ,或許更能理解 Class 和 Method的關係

Class裡面有

(1)property

(2)method

 

namespace WindowsFormsApp1
{
    class fruit
    {
        //propery
        public string name;
        public int price;
        public int number;

        //method

        public fruit(string new_name,int new_price,int new_number)
        {
            name = new_name;
            price = new_price;
            number = new_number;
        }

     
        public int Total_Money()
        {

            return price*number;

        } 

    }
}

 



產生物件

fruit my_fruit_1=new fruit("kiwi",50,5);

 



 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 matt 的頭像
    matt

    My的部落格

    matt 發表在 痞客邦 留言(0) 人氣()