User Tools

Site Tools


net_array

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
net_array [2018/05/31 05:52]
wolfgangriedmann
net_array [2018/09/09 06: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:
-<​code>​local aData as byte[]</​code>​+<​code ​visualfoxpro>local aData as byte[]</​code>​
 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:
-<​code>​aData := byte[]{ 10 }+<​code ​visualfoxpro>aData := byte[]{ 10 }
 aData := <​byte>​ { 1, 2, 3, 4, 5 }</​code>​ aData := <​byte>​ { 1, 2, 3, 4, 5 }</​code>​
 It depends on the compiler settings of your application,​ if the index of your array starts with ''​0''​ (like C#) or with ''​1''​ (like VO). It depends on the compiler settings of your application,​ if the index of your array starts with ''​0''​ (like C#) or with ''​1''​ (like VO).
 Therefore it is better to use the ''​foreach''​ operator to enumerate a static array. Therefore it is better to use the ''​foreach''​ operator to enumerate a static array.
-<​code>​foreach cByte as byte in aData+<​code ​visualfoxpro>foreach cByte as byte in aData
   // Do something   // Do something
 next</​code>​ next</​code>​
 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:​
-<​code>​nIndex := Array.IndexOf( aData, 2 )+<​code ​visualfoxpro>nIndex := Array.IndexOf( aData, 2 )
 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 31: Line 31:
 There are two different types of multidimensional arrays with different syntax: There are two different types of multidimensional arrays with different syntax:
 The jagged arrays or arrays of arrays: The jagged arrays or arrays of arrays:
-<​code>​local aJagged as string[][]+<​code ​visualfoxpro>local aJagged as string[][]
  
 aJagged := <​string[]>​{ <​string>​{ "​X#",​ "​xsharp.info"​ }, <​string>​{ "​C#",​ "​microsoft.com"​ } } aJagged := <​string[]>​{ <​string>​{ "​X#",​ "​xsharp.info"​ }, <​string>​{ "​C#",​ "​microsoft.com"​ } }
 System.Console.WriteLine( aJagged[0][0] )</​code>​ System.Console.WriteLine( aJagged[0][0] )</​code>​
 The jagged arrays are more efficient, but have a (for xBase users) strange syntax to access the members. The jagged arrays are more efficient, but have a (for xBase users) strange syntax to access the members.
 +<code visualfoxpro>​local aJagged as string[][]
 +aJagged := <​string[]>​{string[]{nLen},​ string[]{nLen},​string[]{nLen} }</​code>​
 +At this level, there are no strings in aJagged. Only NULL values.
 +
 +And now (if zero based), it can be filled: ​
 +<code visualfoxpro>​aJagged[0…2][0..nLen-1] := "​Test"​
 +
 +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"</​code>​
 +
 There are also multidimensional arrays: There are also multidimensional arrays:
-<​code>​local aMulti as string[,]+<​code ​visualfoxpro>local aMulti as string[,]
  
 aMulti := string[,​]{2,​2}{ <​string>​{ "​X#",​ "​xsharp.info"​ }, <​string>​{ "​C#",​ "​microsoft.com"​ } } aMulti := string[,​]{2,​2}{ <​string>​{ "​X#",​ "​xsharp.info"​ }, <​string>​{ "​C#",​ "​microsoft.com"​ } }
net_array.txt · Last modified: 2018/09/09 06:20 by wolfgangriedmann