3
Answers

Multi dimensional jagged array of Point

Spark C

Spark C

17y
2.5k
1

Hi,

I am a newbie in C# and I am having problems initializing multi-dimensional jagged arrays.

I want to create a two dimensional array of Points. I am using arrays bcoz I dont know any other easier collection but if anybody knows a better and easy collection please let me know.

I am declaring my array like this: Point[][] gPoints;

In the first dimension I want to store 4 points and each of those dimensions containing 4 points will have jagged array of points. So first I want to initialize the first dimension with 4 points and then later add points dynamically to each dimensions.

My program divides the canvas into small squares of fixed dimensions and for each of those squares there will be different no. of  Points..Below is the initialization which is absolutely incorrect: Please someone correct it...

for (int x = 0; x < Dimension; x++){

gPoints[x] = new Point[Dimension][] {new Point[]{{ new Point( x, x )}, {new Point ( x, y )}, {new Point (y, y )}, {new Point ( y, x ) }}};

}

Answers (3)