我的问题几乎是基本的,但我不知道要这样做。请检查下面的代码。我的基本目标是创建一个公共类,该类将在列表下返回一些静态数据。下面提供了示例类模型。请参见类PaymentMethodDetials
中的两个属性,我想将类PaymentMethodList
中这两个属性的值设置为列表,然后我将在整个c#类模型之外公开使用这些列表值。现在我的问题是paymentList.Add()
Visual Studio不允许我执行Add
方法。我该如何解决?预先感谢
namespace Test.Helpers
{
public class PaymentMethodList
{
List<PaymentMethodDetials> paymentList = new List<PaymentMethodDetials>();
paymentList.Add()//i want to insert data to "PaymentMethodDetials" this class like using "Add" which allowing now
}
public class PaymentMethodDetials
{
public int Id { get; set; }
public string Name { get; set; }
}
}
答案 0 :(得分:4)
尝试一下,希望对您有帮助
namespace Test.Helpers
{
public class PaymentMethodList
{
List<PaymentMethodDetials> paymentList = new List<PaymentMethodDetial();
public PaymentMethodList()
{
paymentList.Add(new PaymentMethodDetials
{
Id=1,
Name="xyz"
});
}
}
public class PaymentMethodDetials
{
public int Id { get; set; }
public string Name { get; set; }
}
}