c#基础知识第九节

类和对象

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();
}

}

原文地址:https://www.cnblogs.com/zhang1997/p/7656678.html