leandropoblet
11 years agoFrequent Contributor
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 ...
- 11 years ago
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