我有一个类型库存的可观察集合 定义为
Observablecollection<Inventory> inventory = new ObservableCollection<Inventory>();
库存有:
inventory.name;
inventory.status;
inventory.place;
如何在每个库存的索引[0]处添加一些字符串,如下所示:
["icescream", inventory.name, inventory.status, inventory.place];
["popcorn", inventory.name, inventory.status, inventory.place];
["popcorn", inventory.name, inventory.status, inventory.place];
["lollipop", inventory.name, inventory.status, inventory.place];
["candy", inventory.name, inventory.status, inventory.place];
这可能吗?
答案 0 :(得分:0)
合适的linq表达式可能如下所示:
var joined = inventory.Select(item => new {value = "Test " + item.name, item});
// than for e.g. you could iterate through and print them out
foreach (var anonymousItem in joined)
{
var item = anonymousItem.item;
const string format = "[\"{0}\", {1}, {2}, {3}];";
Console.WriteLine(format, anonymousItem.value, item.name, item.status, item.place);
}