属性设置的一些异常行为(二)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConTest
{
class Pan
{
public string Name { get; set; }
public double Price { get; set; }
public int Total { get; set; }
/// <summary>
/// 深圳平底锅的价格信息
/// </summary>
public static Pan SZ
{
get
{
return new Pan() {Name="深圳",Price=45.5,Total=100,};
}
}
/// <summary>
/// 上海平底锅的价格信息
/// </summary>
public static Pan SH
{
get
{
return new Pan() { Name = "上海", Price = 46.5, Total = 150, };
}
}
/// <summary>
/// 北京平底锅的价格信息
/// </summary>
public static Pan BJ
{
get
{
return new Pan() { Name = "北京", Price = 48.2, Total = 80, };
}
}
/// <summary>
/// 广州平底锅的价格信息
/// </summary>
public static Pan GZ
{
get
{
return new Pan() { Name = "广州", Price = 43.5, Total = 250, };
}
}
public Pan()
{
}
public Pan(string name ,double price,int total)
{
this.Name = name;
this.Price = price;
this.Total = total;
}
}
}
List<Pan> pans = new List<Pan>() { Pan.BJ, Pan.GZ, Pan.SH, Pan.SZ };
Console.WriteLine("四大城市平底锅的价格基本信息如下:");
foreach (var item in pans)
{
Console.WriteLine("地区:" +item.Name+ "\t平底锅价格:" + item.Price + "\t销量:" + item.Total);
}