Ex. I want to modify the element in list that "id" is matched. I do like this.
for(int i=0;i<list.Count;i++){
if(list[i].id==id){
list[i].data = newData;
break;
}
}
Is there any shorter way to do?
Convert your list to dictionary and use id as a key:
var dictionary = list.ToDictionary(o => o.id);
//...
dictionary[id].data = newData;
list = list.Select(x =>
{
if(x.id == id)
{
x.data = newdata;
break;
}
return x;
}