如果我有一个客户对象,其中有一个Payment属性,它是一个由自定义枚举类型和十进制值组成的字典,例如
Customer.cs
public enum CustomerPayingMode
{
CreditCard = 1,
VirtualCoins = 2,
PayPal = 3
}
public Dictionary<CustomerPayingMode, decimal> Payment;
在客户端代码中,我遇到了向字典添加值的问题,尝试过以下方法:
Customer cust = new Customer();
cust.Payment = new Dictionary<CustomerPayingMode,decimal>()
.Add(CustomerPayingMode.CreditCard, 1M);