c# - How to modify properties of the incoming object without creating a new instance? -


i modify properties of incoming object. how without creating new instance?

i have class

public class report : ireport<reportitem> {     public report()     {         items = new reportitemscollection();     }      public report(ienumerable<reportitem> items)     {         items = new reportitemscollection(items);     }      [datamember(name = "items")]     public reportitemscollection items { get; private set; }      ienumerable<reportitem> ireport<reportitem>.items     {         { return items; }     } } 

and 2 methods

private static report convertreportitems(report report) {     var reportdata = report.items.select(backwardcompatibilityconverter.fromold);     return new report(reportdata); }  public static reportitem fromold(reportitem reportitem) {     reportitem.agentids = new list<guid> { reportitem.agentid };     reportitem.agentnames = new list<string> { reportitem.agent };      return reportitem; } 

it sounds you're trying update properties of each object in collection linq. linq querying, not updating. if want update items in collection, you'll have loop:

foreach(reportitem item in report.items) {    // update item } 

whether should or not question, mechanically that's how would it.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -