Forum Discussion

leandropoblet's avatar
leandropoblet
Frequent Contributor
11 years ago

C# Script Multidimensional array length

Hi,



I'm retrieving some data from a DB and I load it into a multidimensional array.



The thing is, I don't always know the size of the array beforehand, so I'd like to make a function to go through all of it to find the data I'm looking for.



So far so good, except I cannot make that function without knowing the length of the array.



Is there any way to know it?


  • Hi Leandro, are you executing the Script in Test Complete or in a C# Self-Testing and/or Connected Application?


     


    If it is the latter then the following is pertinent in the C# Script documentation




    "3. Do not use JScript statements with and for…in and JScript operators ===, !==, >>> and >>>=. They are not supported in C#. If you use them, you will have to update your code when porting it to a C# application.


    4. In addition, these JScript objects are not currently supported in C# applications: Array, Boolean, Date, Function, Global, Math, Number, Object, RegExp, Error and String."


     


    If you are executing the Script in Test Complete be aware that C# Script is based on JScript therefore has no concept of multi-dimensional arrays, instead you need to use the arrays of arrays model, e.g.


     


    function testArray() {


      // Multi-dimensional array of arrays


      var arr = [ [ 1, 2, 3 ],


                  [ 4, 5, 6 ],


                  [ 7, 8, 9 ] ];


                  


      // Iterate the outer array


      for( var a = 0; a < arr["length"]; a++ ) {


        // Iterate each inner array


        for( b = 0; b < arr[ a ]["length"]; b++ ) {


          Log["Message"]( arr );


        } 


      }


    }


     


    Regards,


    Phil Baird




  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi william, the link you provided is for C# .Net Arrays.


     


    C# Script in Test Complete (to which the OP is referrring) is a derivative of JScript and does not have the Type or Array concepts described in the linked article.


     


    Regards,


    Phil Baird