Friday, December 14, 2012

C# expand(Resize) array for a class

Imagine you had one class connected after another.  This one happens to be the EDI 271...

Difficult to read, however lets continue:


<>
  XmlSerializer SerializerObj = new XmlSerializer(typeof(X12_00501_271));
            XmlNodeReader reader = new XmlNodeReader(this.Utilities.ReturnDocument);
            object obj = SerializerObj.Deserialize(reader);
            X12_00501_271 Cmyobj = (X12_00501_271)obj;
                     
            int lenTS271_2000A_Loop = Cmyobj.TS271_2000A_Loop.Length;
            for (int i = 0; i < lenTS271_2000A_Loop; i++)
            {
                int lenTS271_2000B_Loop = Cmyobj.TS271_2000A_Loop[i].TS271_2000B_Loop.Length;
                for (int j = 0; j < lenTS271_2000B_Loop; j++)
                {
                    int lenTS271_2000C_Loop = Cmyobj.TS271_2000A_Loop[i].TS271_2000B_Loop[j].TS271_2000C_Loop.Length;
                    for (int k = 0; k < lenTS271_2000C_Loop; k++)
                    {
                        int lenTS271_2110C_Loop = Cmyobj.TS271_2000A_Loop[i].TS271_2000B_Loop[j].TS271_2000C_Loop[k].TS271_2100C_Loop.TS271_2110C_Loop.Length;
                        // start
1)                        TS271_2110C_Loop[] TS271_2110C_Loop = Cmyobj.TS271_2000A_Loop[i].TS271_2000B_Loop[j].TS271_2000C_Loop[k].TS271_2100C_Loop.TS271_2110C_Loop;
 2)                       Array.Resize(ref TS271_2110C_Loop, TS271_2110C_Loop.Length + 1);
                        TS271_2110C_Loop[TS271_2110C_Loop.Length - 1] = new TS271_2110C_Loop();

                        3) Cmyobj.TS271_2000A_Loop[i].TS271_2000B_Loop[j].TS271_2000C_Loop[k].TS271_2100C_Loop.TS271_2110C_Loop = TS271_2110C_Loop;

    

<>

1.  Instantiate new copy of the class TS271_2110C_Loop.
2.  Use the resize command to expand the table. 
3.  Load the class  TS271_2110C_Loop back into the original oject:

 Cmyobj.TS271_2000A_Loop[i].TS271_2000B_Loop[j].TS271_2000C_Loop[k].TS271_2100C_Loop.TS271_2110C_Loop = TS271_2110C_Loop;

 

No comments:

Post a Comment