我有這樣一個模型:列表<T>添加項目
class PayPalModel
{
public class Payment
{
public string intent { get; set; }
public Payer payer { get; set; }
public List<Transaction> transactions { get; set; }
}
public class Payer
{
public string payment_method { get; set; }
public List<Funding_Instruments> funding_instruments { get; set; }
}
public class Funding_Instruments
{
public Credit_Card credit_card { get; set; }
}
public class Credit_Card
{
public string number { get; set; }
public string type { get; set; }
public int expire_month { get; set; }
public int expire_year { get; set; }
public string cvv2 { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public Billing_Address billing_address { get; set; }
}
public class Billing_Address
{
public string line1 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string country_code { get; set; }
}
public class Transaction
{
public Amount amount { get; set; }
public string description { get; set; }
}
public class Amount
{
public string total { get; set; }
public string currency { get; set; }
public Details details { get; set; }
}
public class Details
{
public string subtotal { get; set; }
public string tax { get; set; }
public string shipping { get; set; }
}
}
,我試圖將值添加到它,但我被陷在如何添加funding_instruments
。
我曾嘗試以下,但它不會讓我再補充一個新的Credit_Card
這是我的代碼:
PayPalWrapper.PayPalModel.Payment payment = new PayPalWrapper.PayPalModel.Payment();
payment.intent = "sale";
payment.payer = new PayPalWrapper.PayPalModel.Payer();
payment.payer.payment_method = "credit_card";
payment.payer.funding_instruments = new List<PayPalWrapper.PayPalModel.Funding_Instruments>();
payment.payer.funding_instruments.Add(new PayPalModel.Credit_Card() { first_name = "test" });
但它給錯誤
Error 1 The best overloaded method match for 'System.Collections.Generic.List<PayPalWrapper.PayPalModel.Funding_Instruments>.Add(PayPalWrapper.PayPalModel.Funding_Instruments)' has some invalid arguments
我只是不能算出添加Credit_Card的語法!
任何人都可以幫忙嗎?
@Jontatas貝寶的文檔可能不會幫助您解決問題。這是一個向列表添加錯誤類型的情況,就是這樣。 – Joe
請務必閱讀整個錯誤消息。它應該符合'不能從'PayPalWrapper.PayPalModel.Credit_Card'轉換爲'PayPalWrapper.PayPalModel.Funding_Instruments'。這是你做錯了什麼的明確指標。 – sloth
感謝您的反對! - 我們都必須學習...... –