我有以下代码,问题是当我尝试将国家/地区分配给客户时,出现错误。我需要知道如何分配声明为枚举的属性?我将在 linq 表达式中使用它,还有其他使用枚举的方法吗?
var customers = new Customer[] {
new Customer { Name= "Badhon",City= "Dhaka",Country=Countries.Country.Bangladesh,Order= new Orders[] {
new Orders { OrderID=1,ProductID=1,Quantity=2,Shipped=false,Month="Jan"}}},
new Customer {Name = "Tasnuva",City = "Mirpur",Country =Countries .Country .Italy,Order =new Orders[] {
new Orders { OrderID=2,ProductID=2,Quantity=5,Shipped=false,Month="Feb"}}}
}
我enum
的定义如下:
public class Countries
{
public enum Country {Italy,Japan,Bangladesh};
}
Customer
如下:
public class Customer
{
public string Name;
public string City;
public Countries Country;
public Orders[] Order;
public override string ToString()
{
return string.Format("Name: {0} - City: {1} - Country: {2}", this.Name, this.City, this.Country);
}
}