G
Guest
so I've read these blog entries and such on why the not allowing non-zero based array index. turns out, you can make it work in C#. this code coming straight from the .NET SDK 1.1 under Array.CreateInstance. my question is, is this there for VB compatibility reason or something
using System
public class SamplesArray
public static void Main()
// Creates and initializes a multidimensional Array of type String
int[] myLengthsArray = new int[2] { 3, 5 }
int[] myBoundsArray = new int[2] { 2, 3 }
Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray )
for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++
for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )
int[] myIndicesArray = new int[2] { i, j }
myArray.SetValue( Convert.ToString(i) + j, myIndicesArray )
// Displays the lower bounds and the upper bounds of each dimension
Console.WriteLine( "Bounds:\tLower\tUpper" )
for ( int i = 0; i < myArray.Rank; i++
Console.WriteLine( "{0}:\t{1}\t{2}", i, myArray.GetLowerBound(i), myArray.GetUpperBound(i) )
// Displays the values of the Array
Console.WriteLine( "The Array contains the following values:" )
PrintValues( myArray )
public static void PrintValues( Array myArr )
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator()
int i = 0
int cols = myArr.GetLength( myArr.Rank - 1 )
while ( myEnumerator.MoveNext() )
if ( i < cols )
i++
} else
Console.WriteLine()
i = 1
Console.Write( "\t{0}", myEnumerator.Current )
Console.WriteLine()
using System
public class SamplesArray
public static void Main()
// Creates and initializes a multidimensional Array of type String
int[] myLengthsArray = new int[2] { 3, 5 }
int[] myBoundsArray = new int[2] { 2, 3 }
Array myArray=Array.CreateInstance( typeof(String), myLengthsArray, myBoundsArray )
for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++
for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )
int[] myIndicesArray = new int[2] { i, j }
myArray.SetValue( Convert.ToString(i) + j, myIndicesArray )
// Displays the lower bounds and the upper bounds of each dimension
Console.WriteLine( "Bounds:\tLower\tUpper" )
for ( int i = 0; i < myArray.Rank; i++
Console.WriteLine( "{0}:\t{1}\t{2}", i, myArray.GetLowerBound(i), myArray.GetUpperBound(i) )
// Displays the values of the Array
Console.WriteLine( "The Array contains the following values:" )
PrintValues( myArray )
public static void PrintValues( Array myArr )
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator()
int i = 0
int cols = myArr.GetLength( myArr.Rank - 1 )
while ( myEnumerator.MoveNext() )
if ( i < cols )
i++
} else
Console.WriteLine()
i = 1
Console.Write( "\t{0}", myEnumerator.Current )
Console.WriteLine()