I have a repository with a public List<someView> list;
Is it not possible to get an item with linq like this and just update/replace the whole object so the object in the list is updated globally right away?
...
var item = list.SingleOrDefault(m => m.Id== viewModel.Id);
if (item != null)
{
item = viewModel;
}
...
No because item
is just a local variable, but you can use the indexer of the list:
int index = list.FindIndex(m => m.Id == viewModel.Id);
if(index >= 0)
list[index] = viewModel;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With