0

I wonder if there's a way to convert jagged array , say [3][] into three one-dimensional arrays ?

2 Answers 2

2

Something like this? Assuming jagged is defined as int[3][]:

int[] first = jagged[0];
int[] two = jagged[1];
int[] three = jagged[2];

Each element in the first dimension of jagged is an array in and of itself - there is no need to convert.

Sign up to request clarification or add additional context in comments.

Comments

1

It already is three one-dimensional arrays, effectively. Jagged arrays are not treated specially by the CLR, they are simply arrays of arrays. You just index the outer array to get one of the inner arrays.

Example:

var array1 = jaggedArray[0];
var array2 = jaggedArray[1];
var array3 = jaggedArray[2];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.