Lambda expressions - set the value of one property in a collection of objects based on the value of
- by Michael Rut
I'm new to lambda expressions and looking to leverage the syntax to set the value of one property in a collection based on another value in a collection
Typically I would do a loop:
class item{
public string name {get;set;}
public string value {get;set;}
}
class business
{
item item1 = new item(name="name1");
item item2 = new item(name="name2");
item item3 = new item(name="name3");
Collection<item> items = new Collection() {item1,item2,item3};
//This is what I want to simplify
for( int i = 0; i < items.count; i++)
{
if(items[i].item.name == "name2")
{
//set the value
items[i].item.value = "value2";
}
}
}