none
How to set property of two nested list class? RRS feed

  • Question

  • Hello,

    Actually I'm facing one issue that I would like to set the propert of a object with same property of another object of same type.

    I did as below. It is working fine but I would like to avoid many loops. In the below code, I need to set the selected point from another object that I'm sending as parameter. Please help me.

    public void SetAllCurrentPoint(GraphicData mainGraphicData)
    {
        foreach (GraphInfo graphInfo in mainGraphicData.ListGraph)
        {
            foreach (CurveInformation curve in graphInfo.ListCurves)
            {
                this.GraphData.ListGraph.ForEach(delegate(GraphInfo info)
                {
                    CurveInformation data = info.ListCurves.Find(delegate(CurveInformation information)
                    {
                        return curve.CurveInfo.Name == information.CurveInfo.Name;
                    });

                    if (data != null)
                    {
                        data.CurveInfo.SelectedPoint = curve.CurveInfo.SelectedPoint;
                    }
                });
            }
        }
    }

    Thanks and Regards,

    Hari


    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you Happy Programming! Hari

    Friday, June 29, 2018 11:38 AM

All replies

  • If there is no correlation between the 2 points other than an arbitrary data point then unless you radically change your design nested loops is the only solution. It is unclear what would trigger this sync but it looks like maybe you have some option in your UI to do this so enumeration is pretty much the only option. If there is some sort of relationship between the mainGraphicData and ListGraph then you could store a reference between the objects and then skip the find part but otherwise enumeration is inevitable.

    The most you can probably do is clean up the enumeration behind LINQ. It's still going to happen, just not you doing it. I could see you collapse the first 2 foreach into a LINQ select. Then I could see the use of a join clause to combine it with the ListGraph data. From there you could create an anony type that connects the main and list data points. Finally you can run a transform (probably a foreach) to set the point on the linegraph to the maingraph. This won't be any faster than what you have probably, just less code.


    Michael Taylor http://www.michaeltaylorp3.net

    Friday, June 29, 2018 2:36 PM
    Moderator