: code tutorial (v3)

Lesson 9: Using Array Proxy Types

Introduction

Arrays are fairly straightforward to use, once you remember that proxy arrays are not .NET arrays. .NET does not allow a type to extend that .NET Array type, which makes it impossible for us to make proxy array types full .NET arrays. The best we can do is to create types that are usable as if they were .NET array types (at least largely).

The biggest differences between real .NET arrays and proxy arrays can be found in the following areas:

On the other hand, leaving these limitations aside, everything else works just as expected:

Here is an example of how you might use a one-dimensional proxy array for the java.lang.String type with space for 4 string elements:

StringArray    arrStr = new StringArray( 4 );

Console.WriteLine( "The array size is {0}", arrStr.Length );

arrStr[ 0 ] = "test";
arrStr[ 1 ] = "value";
arrStr[ 2 ] = null;
arrStr[ 3 ] = "...";

foreach( string s in arrStr )
    Console.WriteLine( "Element: {0}", s != null ? s : "(null)" );

Array Type Names

The following table gives you the overview of how Java and .NET proxy array type names are mapped:

Java Type
.NET Type
boolean[]
Codemesh.JuggerNET.boolArray
byte[]
Codemesh.JuggerNET.byteArray
char[]
Codemesh.JuggerNET.charArray
double[]
Codemesh.JuggerNET.doubleArray
float[]
Codemesh.JuggerNET.floatArray
int[]
Codemesh.JuggerNET.intArray
long[]
Codemesh.JuggerNET.longArray
short[]
Codemesh.JuggerNET.shortArray
java.lang.Object[]
Java.Lang.ObjectArray
java.lang.Object[][]
Java.Lang.ObjectArrayArray
java.util.Map[]
Java.Util.MapArray

Please note that the type names for arrays of reference-type elements are in the same namespaces as their elements.