我有一堂课:
public class CustomerItem
{
public CustomerItem(IEnumerable<SomeProperty> someProperties,
IEnumerable<Grade> grades,
decimal unitPrice, int quantity, string productCode)
{
SomeProperties = someProperties;
Grades = grades;
UnitPrice = unitPrice;
Quantity = quantity;
ProductCode = productCode;
}
public string ProductCode { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public IEnumerable<Grade> Grades { get; set; }
public IEnumerable<SomeProperty> SomeProperties { get; set; }
}
然后我有一个:
public IEnumerable<CustomerItem> CustomerItems {get; set;}
我能够得到CustomerItems
相关数据的填充。
现在,我想将所有项目添加CustomerItems
到NameValueCollection
.
NameValueCollection target = new NameValueCollection();
// I want to achieve
target.Add(x,y); // For all the items in CustomerItems
// where - x - is of the format - Line1 - for first item like "Line" + i
// "Line" is just a hardcodedvalue to be appended
// with the respective item number in the iteration.
// where - y - is the concatenation of all the values for that specific line.
如何做到这一点?