我已将数据分配到如下列表中。
foreach (var items in niledetails)
{
cruiseDetails.Add(new CruiseDetails()
{
mainID = items.cruiseID,
idL = items.idlength,
mainimageUrl = items.cruiseimageUrl,
adultPrice = items.adultprice,
location = items.cruiseLocation,
numberofDays = items.numberofdays,
description = items.description,
embarkationP = items.embarkationport,
cruiseTyp = items.cruisetype,
childPrice = items.childprice,
totalPrice = items.totalprice,
farecode = items.referenceNumber,
experience = items.cruiseName,
fullcategoryname = items.cruiseCabname
});
}
这很好用。这有30个对象,每个对象有14个键/值。现在我想要的是为列表中的每个对象添加额外的值。
这意味着这样的事情
for(int i=0;i<cruiseDetails.Count();i++)
{
//for each object I want to add another key value( 15th) for all 30 objects.
}
我该怎么做?希望你的帮助。
注意:我不是在寻找这个。 EX:
cruiseDetails.Insert(0, new someModel() { city = "All"});
答案 0 :(得分:2)
https://hostname.com/key=value
试试这段代码
答案 1 :(得分:1)
试试这个:
foreach (CruiseDetails myCruiseDetail in cruiseDetails){
myCruiseDetail.myNewKey = myNewValue;
}
答案 2 :(得分:0)
在循环中设置属性
for(int i=0;i<cruiseDetails.Count();i++)
{
cruiseDetails[i].mynewproperty = somevalue;
}
答案 3 :(得分:0)
尝试这样的事情:
List<Tuple<int, CruiseDetails>> list = new List<Tuple<int, CruiseDetails>>();
CruiseDetails> sourceCruises = new List<CruiseDetails>();
int i = 0;
foreach (var c in sourceCruises)
{
list.Add(new Tuple<int, CruiseDetails>(i, c));
i++;
}