net_array
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
net_array [2018/02/12 19:01] – wolfgangriedmann | net_array [2018/09/09 04:20] (current) – wolfgangriedmann | ||
---|---|---|---|
Line 8: | Line 8: | ||
A static array is defined by any datatype, followed by an open and a close square bracket: | A static array is defined by any datatype, followed by an open and a close square bracket: | ||
- | < | + | < |
To initialize such an array, you need to specify also the dimension, or to specify the values, casting to the right datatype: | To initialize such an array, you need to specify also the dimension, or to specify the values, casting to the right datatype: | ||
- | < | + | < |
aData := < | aData := < | ||
It depends on the compiler settings of your application, | It depends on the compiler settings of your application, | ||
Therefore it is better to use the '' | Therefore it is better to use the '' | ||
- | < | + | < |
// Do something | // Do something | ||
next</ | next</ | ||
Since an array is also an object, it has its own properties and methods. | Since an array is also an object, it has its own properties and methods. | ||
But the static methods of the array class are much more interesting: | But the static methods of the array class are much more interesting: | ||
- | < | + | < |
cByte := Array.Find( aData, { a as byte => a == 2 } ) | cByte := Array.Find( aData, { a as byte => a == 2 } ) | ||
cByte := Array.Find( aData, FindByte ) | cByte := Array.Find( aData, FindByte ) | ||
Line 28: | Line 28: | ||
endif | endif | ||
return false</ | return false</ | ||
+ | |||
+ | There are two different types of multidimensional arrays with different syntax: | ||
+ | The jagged arrays or arrays of arrays: | ||
+ | <code visualfoxpro> | ||
+ | |||
+ | aJagged := < | ||
+ | System.Console.WriteLine( aJagged[0][0] )</ | ||
+ | The jagged arrays are more efficient, but have a (for xBase users) strange syntax to access the members. | ||
+ | <code visualfoxpro> | ||
+ | aJagged := < | ||
+ | At this level, there are no strings in aJagged. Only NULL values. | ||
+ | |||
+ | And now (if zero based), it can be filled: | ||
+ | <code visualfoxpro> | ||
+ | |||
+ | aJagger[0][0] := "First String element in the 1st array" | ||
+ | aJagged[1][2] := "Hello !" | ||
+ | aJagged[2][nLen-1] := "Last String element in the last array"</ | ||
+ | |||
+ | There are also multidimensional arrays: | ||
+ | <code visualfoxpro> | ||
+ | |||
+ | aMulti := string[, | ||
+ | System.Console.WriteLine( aMulti[0,0] )</ | ||
+ | Of course you can use them also in more than 2 dimensions. | ||
In the daily coding the [[collections|Collections]] are much more important, because they can be resized. | In the daily coding the [[collections|Collections]] are much more important, because they can be resized. | ||
Line 34: | Line 59: | ||
The VO dynamic arrays pay a high price for their flexibility: | The VO dynamic arrays pay a high price for their flexibility: | ||
+ | But the X# runtime (ready from June 2018) introduces typed arrays, so you can have both: the flexibility of the VO array and the compiler checks of the .NET array. | ||
- | You can find more help in the MSDN page [[https:// | + | You can find more help informations about .NET arrays |
net_array.txt · Last modified: 2018/09/09 04:20 by wolfgangriedmann