我不明白这一点。我能够将我的第一枚枚举值赋予int而不是第二枚呢?不能将第二枚枚举值转换为int?
public enum PayPalTransactionType
{
Authorization = 0, // Debit
Capture = 1, // Credit
Refund = 2,
Void = 3
}
public string GetPayPalTransCode(PayPalServiceBase.PayPalTransactionType payPalTransactionType)
{
string actionCode = string.Empty;
switch (payPalTransactionType)
{
case (int)PayPalServiceBase.PayPalTransactionType.Authorization:
actionCode = "Debit";
break;
case (int)PayPalServiceBase.PayPalTransactionType.Capture:
actionCode = "Credit";
break;
}
return actionCode;
}
在我的第二个case语句,我得到这个错误铸造:
Cannot implicitly convert type
int
toPayPalTransactionType
. An explicit conversion exists (are you missing a cast?)
请编辑您的问题,将所有的代码放在代码块中,现在很混乱。谢谢 – 2010-02-08 14:18:19
@Marcel:完成 – AakashM 2010-02-08 14:19:32
为什么在你的case语句中将'enum'强制转换为'int'?实际上你根本不需要施展这些。 – 2010-02-08 14:22:12