[英]Assign static value to class from another class
My question is pretty much basic but I am not getting idea to do it. 我的问题几乎是基本的,但我不知道要这样做。 Please check the code bellow. 请检查下面的代码。 My basic goal is to make a public class which will return some static data under a list. 我的基本目标是创建一个公共类,该类将在列表下返回一些静态数据。 The example class model is provided bellow. 下面提供了示例类模型。 See in class PaymentMethodDetials
has two properties and I want to set value of this two property from class PaymentMethodList
as a list then I will be using those list values outside this whole c# class model publically. 在类PaymentMethodDetials
有两个属性,我想从类PaymentMethodList
设置这两个属性的值作为列表,然后我将在整个c#类模型之外公开使用这些列表值。 Now my problem is paymentList.Add()
visual studio not allowing me to do Add
method. 现在我的问题是Visual Studio的paymentList.Add()
不允许我执行Add
方法。 How can I fix that? 我该如何解决? Thanks in advance 提前致谢
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; }
}
}
Try this , hope this helps 试试这个,希望对您有所帮助
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; } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.