C#C
C#4y ago
Bujju

Modify property of object in List [Answered]

I have a struct like this:

public struct MyStruct
{
    public ulong Id { get; set; }

    public string MyProperty { get; set; }
}

And I have a
List<MyStruct>
. I want to modify
MyProperty
for a certain
MyStruct
in the list, using the
Id
property. I tried this:

MyList.Where(x => x.Id == id).ToList().ForEach(x => x.MyProperty = myVariable);

But it didn't work.
Was this page helpful?