2 回答
TA贡献2003条经验 获得超2个赞
这个问题缺少更多的上下文信息,大概写了下,不知是否正确,供参考。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | using System;
namespace Car { class Car { //将品牌、型号、颜色、价格定义为属性 public string Brand { get; set; } public string Model { get; set; } public string Color { get; set; } public decimal Price { get; set; }
//构造函数 public Car(){ }
//显示汽车信息 public override string ToString() { return String.Format("品牌:{0}, 型号:{1}, 颜色:{2}, 价格:{3}.",Brand,Model,Color,Price); }
}
class Program { //控制台测试: static void Main(string[] args) { Car car1 = new Car(); car1.Brand = "奔驰"; car1.Model = "SLR722"; car1.Color = "黑色"; car1.Price = 100.00m; Console.WriteLine("汽车1的信息为-{0}",car1.ToString());
Car car2 = new Car() { Brand = "宝马", Model = "X0", Color = "银色", Price = 120.00m, }; Console.WriteLine("汽车2的信息为-{0}", car2.ToString());
Console.ReadKey(); } } } |
- 2 回答
- 0 关注
- 644 浏览
添加回答
举报