0

I have to build a jagged array of 2D arrays but I get the error "A nested array initializer is expected". My code is similar to this:

double[,] a1 = new double[,] { { 1 } };
double[,] a2 = new double[,] { { 2 } };
double[,] a3 = new double[,] { { 3 } };
double[,][] b = new double[,][] { a1, a2, a3 };

Why do I get that error? How can I solve the problem?

1 Answer 1

2

A single dimensional array of two dimensional arrays of doubles is a double[][,], not a double[,][]. With your current type it's expecting a two dimensional array of single dimensional arrays of doubles, which isn't what you're providing.

This is exactly why you shouldn't use a type like this. You probably want to have a custom type that composes a two dimensional array, and have a single array of that custom type. It'll be far easier to work with that without confusing yourself.

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

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.