© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
12 replies
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; }
}
public struct MyStruct
{
    public ulong Id { get; set; }

    public string MyProperty { get; set; }
}

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

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

But it didn't work.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

List as a field of an object. [Answered]
C#CC# / help
4y ago
How do I easily modify *any* property/object/nested object of C# deserialized .json?
C#CC# / help
2y ago
❔ DateTime Property [Answered]
C#CC# / help
4y ago
WPF revalidate the object on any property change [Answered]
C#CC# / help
4y ago