1. 程式人生 > >c#基礎知識第九節

c#基礎知識第九節

類和對象 成員 public void 特征 pub ati args main

類和對象

class Dog
{
//共同特征,品種(字段)
public string breed;
//行為, 犬叫(方法)
public void Shout ()
{
Console.WriteLine(breed + "汪汪汪!");
}
}

class Program
{
static void Main(string[] args)
{
//創建對象的語法:類名 對象名稱 =new 類名();
Dog dog = new Dog();
//創建對象後,可以通過對象的引用來訪問對象的所有成員。
dog.breed = "沙皮狗";
dog.Shout();
}

}

c#基礎知識第九節