using System; //此处引用System是后面要调用显示类Console public class Department { //创建一个私有字段departname,此字段不能被外界函数访问 private string departname=string.Empty; public string Departname { get => departname; set => departname = value; } //外籍访问私有字段的入口为公共函数Departname,快速添加此函数的快捷键是ctrl+R然后ctrl+E; } public class Departmentmain { public static int Main(string[] args) //public void Main(string[] args) //另一种写法为public void Main(string[] args)需要将末尾的return 0 删除 { Department d = new Department(); d.Departname = "Communication"; Console.WriteLine("The Department is :{0}", d.Departname); Console.ReadKey(); return 0; } }