TWO DIMENSIONAL C# ARRAY INITIALIZED WITH 2 OTHER ARRAYS

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
C# 
C#
 1129  View(s)
Ratings:
Rate this:

I'm a bit new to C# and I don't understand how to make this work:

private static readonly Unit[,] UNIT_TYPES = new Unit[,]{LENGTH_UNITS, ANGLE_UNITS};

private static readonly Unit[] LENGTH_UNITS = new Unit[3]{Unit.Millimeters, Unit.Inches, Unit.Centimeters};

private static readonly Unit[] ANGLE_UNITS = new Unit[2]{Unit.Degrees, Unit.Radians};

I'm getting the error "A nested array initializer was expected" on the UNIT_TYPES variable. It seems to not except the fact that LENGTH_UNITS and ANGLE_UNITS will be ready at compile time. What's the best way to rewrite this?

Thanks!

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Two dimensional C# Array initialized with 2 other arrays

    Hi Goti, 


    You're trying to initialize a rectangular array

    int[,] Position = { {2 , 3}, {4 , 5}, {6 , 7} };

    this like three array inside a array Eq:

         int[] IN0 = { 2, 3 };

         int[] IN1 = { 4, 5 };

         int[] IN2 = { 6, 7 };``

         int[][] Final = { IN0, IN1, IN2 };

    int[,] = the way of create Rect some as grids. int[][] = the way of accessing grid or 2d images

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!