how to loop array inside array in c#?

  • Hi All,

    I am new to c# and need your help in understanding below coding in C#.

    My input code:

    public partial class Diag

    {

    private DiagnosisType[] axisIField;

    private DiagnosisType[] axisIIField;

    private DiagnosisType[] axisIIIField;

    [System.Xml.Serialization.XmlArrayItemAttribute("Diagnosis", IsNullable = false)]

    public DiagnosisType[] axisI

    {

    get

    {

    return this.axisIField;

    }

    set

    {

    this.axisIField = value;

    }

    }

    [System.Xml.Serialization.XmlArrayItemAttribute("Diagnosis", IsNullable = false)]

    public DiagnosisType[] axisII

    {

    get

    {

    return this.axisIIField;

    }

    set

    {

    this.axisIIField = value;

    }

    }

    /// <remarks/>

    [System.Xml.Serialization.XmlArrayItemAttribute("Diagnosis", IsNullable = false)]

    public DiagnosisType[] axisIII

    {

    get

    {

    return this.axisIIIField;

    }

    set

    {

    this.axisIIIField = value;

    }

    }

    }

    **My XML File has data like**

    <Diag>

    -<axisI>

    - <diagnosis>

    <flag>true</flag>

    <id>1</id>

    </diagnosis>

    </axisI>

    <axisII/>

    -<axisIII>

    - <diagnosis>

    <flag>false</flag>

    <id>2</id>

    </diagnosis>

    </axisIII>

    </diag>

    **Output collection**

    Public class Create{

    DiagCreate[] DiagnosesOutput;

    and its initialiaztion ;

    }

    public class DiagCreate

    {

    flag;

    id;

    public string flag {

    get {

    return this.flagField;

    }

    set {

    if ((object.ReferenceEquals(this.flagField, value) != true)) {

    this.flagField = value;

    this.RaisePropertyChanged("flag");

    }

    }

    }

    Same thing for ID;

    }

    Now I have to loop through diag ->all the axis->look for all diagnosis->map it to output diagnosis.

    create.Diagnosisoutput[0].flag=diag.axisI.diagnosis.flag;

    Create.Diagnosisoutput[0].id=diag.axisI.diagnosis.id;

    create.Diagnosisoutput[1].flag=diag.axisIII.diagnosis.flag;

    Create.Diagnosisoutput[1].id=diag.axisIII.diagnosis.id;

    create.DiagnosesOutput= some array(this array will have all the diagnosis flag, id from input).

    how to loop array and loop again inside that array and then assign the values to output array?

    Any help is greatly appreciated!!

  • Sorry, this is a SQL Server forum: you won't have many people answering c# questions here.

    I suggest that you post your question in places like stackoverflow.

    -- Gianluca Sartori

  • Even posted on a proper forum this question lacks clarity. It is not at all clear what you are trying to do. Have you looked at the FOR EACH loop? This sounds like exactly what you need and maybe they need to be nested but it is hard to say.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply