我有2个班级:Customer.class和Order.class。在Order.class中有一个字段Customer客户;在客户类中有一个方法CreateOrder,创建一个新订单,然后将此客户设置为其客户,然后返回刚刚创建的订单。有办法吗?
这是C#类的作业。
class Customer{
public int ID{get; set;}
public String Name{get; set;}
public Array<Order> OrderArray{get; set;}
public Order createOrder(){
Order order = new Order(){Customer this.customer} //TODO
OrderArray.add(order);
return order;
}
}
class Order{
public int ID{get; set;}
public Customer Customer{get; set;}
public override String ToString(){
return "Order["+ID+"] is ordered by "+Customer.Name;
}
}