• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C# Equivalent to Java Arrays

Unsized Array

Java C#
int[] myArray = null; int[] myArray = null; //no change

Sized Array

Java C#
int[] myArray = new int[2]; int[] myArray = new int[2]; //no change

Access Array Element

Java C#
x = myArray[0]; x = myArray[0]; //no change

Jagged Array

Java C#
int[][] myArray = new int[2][]; int[][] myArray = new int[2][]; //no change

Rectangular Array

Java C#
int[][] myArray = new int[2][3]; int[][] myArray = RectangularArrays.ReturnRectangularIntArray(2, 3);

//----------------------------------------------------------------------------------------
// Copyright © 2007 - 2017 Tangible Software Solutions Inc.
// This class can be used by anyone provided that the copyright notice remains intact.
//
// This class includes methods to convert Java rectangular arrays (jagged arrays
// with inner arrays of the same length).
//----------------------------------------------------------------------------------------
internal static class RectangularArrays
{
    internal static int[][] ReturnRectangularIntArray(int size1, int size2)
    {
        int[][] newArray = new int[size1][];
        for (int array1 = 0; array1 < size1; array1++)
        {
            newArray[array1] = new int[size2];
        }

        return newArray;
    }
}


Use Java to C# Converter to convert from Java to C#.     

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.