How to update a List in C# -
ilist<receiptallocationmaster> objreceiptmaster = (ilist<receiptallocationmaster>)session["allocationresult"]; public class receiptallocationmaster { public string application { get; set; } public list<users> users { get; set; } } public class users { public string name { get; set; } public string surname { get; set; } }
i need update above list value application = "applicationame"
, users surname = "surname"
same list.
just iterate on list , modify matched items:
(int = 0; < objreceiptmaster.count; i++) { var item = objreceiptmaster[i]; if (item.application == "applicationname" && item.users.any(x => x.surname == "surname")) objreceiptmaster[i] = new receiptallocationmaster(); }
instead of new receiptallocationmaster()
can write modification data logic.
Comments
Post a Comment