I’m hoping I named this question right and that I can explain properly what I mean. I have a list<> of a ViewModel that has been populated from the DB and in my controller I am trying to access a specific single item of that list by one of the item’s properties values and change another property value.
For example my model might have a couple of properties:
public int Id { get; set; }
public bool IsChanged { get; set; }
and I want to access it by the ‘Id’ and change the ‘IsChanged’ property like so (I’m using #’s around the part I’m not sure about)
list.#(select item in the list by it's Id)#.IsChanged = true;
I hope this makes sense and even if you may have a good link to a tutorial,
Thanks 🙂
If I understand correctly, using
Singlewould lead to a null error if there are no matches, I would rather prefer using aSingleOrDefaultwhich would return a null if there is no match… Here is probably a safe approach:And this is by far the best book I have read on LINQ…LINQ to Objects Using C# 4.0
Cheers…