Menu

Structure Array

jlam9012
2014-04-07
2014-04-08
  • jlam9012

    jlam9012 - 2014-04-07

    Hi - I am having trouble creating an array of structures.

    Here is what I have:

    MLStructure structArray = new MLStructure(id, new int[] {3, 1});

    MLStructure structMember = new MLStructure(id, new int[] {1, 1});
    structMember["field"] = new MLInt32("field", new int[] {100}, 1);

    structAray[id, 0] = structMember;

    I thought this would assign a structure "structMember" to the first position in the structArray, but it does not and just makes structArray an empty double.

    Any help would be greatly appreciated. Thanks!

     
    • Tobias

      Tobias - 2014-04-08

      Its easier than you think:

      string id = "myID";
      MLStructure structArray = new MLStructure(id, new int[] {3, 1}); // declare 3 structs
      structArray ["myInt", 0] = new MLInt32("", new int[] { 41 }, 1); // myID[1].myInt = 41
      structArray ["myInt", 1] = new MLInt32("", new int[] { 43 }, 1); // myID[2].myInt = 43
      structArray ["myString", 2] = new MLChar("", "hello"); // myID[3].myString = "hello"
      

      I also have added some lines at the bottom of the [Usage Examples].

       

      Related

      Wiki: Usage Examples


Log in to post a comment.