I have the following list and class:
List<MyClass> MyList
public class MyClass
{
public int id { get; set; }
public bool checked { get; set; }
}
I also have the two variables:
int idToFind = 1234;
bool newcheckedvalue = true;
What I need to do is search the list and find the MyClass object where the id equals that value of idToFind. Once I have the object in the list, I then want to change the value of the checked property in the class to that of the newcheckedvalue value.
LINQ seems to be the solution to this problem, I just can't get the expression right. Can I do this in a single LINQ expression?
ids are unique across instances you could put them in aDictionary<int, MyClass>instead then it would be as simple asMyDictionary[idToFind].checked = newcheckedvalue;.