codesamples:arrayhelper
Array access with 0-based and 1-based array
This code is a sample how to write code that works with both 0-based and 1-based array, independently from the current compiler option.
function Start( ) as void local aData as string[] local nLen as int local nI as int aData := <string>{ "one", "two", "three", "four", "five", "six", "seven" } nLen := aData:Length - 1 + __ARRAYBASE__ for nI := __ARRAYBASE__ upto nLen System.Console.WriteLine( String.Format( "member {0} is {1}", nI:ToString(), aData[nI] ) ) next for nI := aData:FirstIndex() upto aData:LastIndex() System.Console.WriteLine( String.Format( "member {0} is {1}", nI:ToString(), aData[nI] ) ) next foreach cString as string in aData System.Console.WriteLine( String.Format( "member is {0}", cString ) ) next return static class ArrayHelper static method FirstIndex( self aArray as System.Array ) as int return __ARRAYBASE__ static method LastIndex( self aArray as System.Array ) as int local nLength as int nLength := aArray:Length - 1 + __ARRAYBASE__ return nLength end class
codesamples/arrayhelper.txt · Last modified: 2018/05/23 09:17 by wolfgangriedmann