用C#控制台应用写定义一个建筑物类Building要求1字段包括地址、楼层数、竣工时间、所有者;2构造函数中设置所有者并定义一个方法显示类的各个字段信息;3为各私有字段添加相应的属性其中所有者只能读不能写其余属性均可读可写;4命名空间与头文件可以省略只写类的定义部分即可。
class Building { private string address; private int floors; private int completionYear; private string owner;
public Building(string owner)
{
this.owner = owner;
}
public string Address
{
get { return address; }
set { address = value; }
}
public int Floors
{
get { return floors; }
set { floors = value; }
}
public int CompletionYear
{
get { return completionYear; }
set { completionYear = value; }
}
public string Owner
{
get { return owner; }
}
public void DisplayInformation()
{
Console.WriteLine("Address: {0}", address);
Console.WriteLine("Floors: {0}", floors);
Console.WriteLine("Completion Year: {0}", completionYear);
Console.WriteLine("Owner: {0}", owner);
}
原文地址: https://www.cveoy.top/t/topic/fpl0 著作权归作者所有。请勿转载和采集!