User Tools

Site Tools


net_array

This is an old revision of the document!


.NET Arrays

Compared with the VO and Vulcan.NET dynamic arrays, the .NET arrays are very limited.

They cannot grow, cannot shrink and cannot be sorted, and they can contain only elements of one datatype (or class). Of course, the could contain data of type object, and in an object you can store any data, but this does not changes the biggest disadvantage: they remain fixed. Of course, they are very fast.

The major use you will probably find for such arrays is that many .NET methods return an array. The best sample may be the handling of binary data in form of a array of bytes:

A static array is defined by any datatype, followed by an open and a close square bracket:

local aData as byte[]

To initialize such an array, you need to specify also the dimension, or to specify the values, casting to the right datatype:

aData := byte[]{ 10 }
aData := <byte> { 1, 2, 3, 4, 5 }

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.

foreach cByte as byte in aData
  // Do something
next

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:

nIndex := Array.IndexOf( aData, 2 )
cByte := Array.Find( aData, { a as byte => a == 2 } )
cByte := Array.Find( aData, FindByte )
	
static method FindByte( b as byte ) as logic
if b == 2
  return true
endif
return false
net_array.1517768553.txt.gz · Last modified: 2018/02/04 18:22 by wolfgangriedmann