Majid Rafei
Majid Rafei

Reputation: 97

How to initialize an array which has already declared in C#?

I have already declared an array:

double[,] g_bessel = new double[2, 2];

And, I want to initialize it at another place:

{{1,2},{3,4}}

How can I initialize the matrix at a once and not cell by cell?

I mean something like this:

g_bessel = {{1,2},{3,4}};

Upvotes: 0

Views: 231

Answers (1)

Yuri Dorokhov
Yuri Dorokhov

Reputation: 726

You must use operator "new" for initialize new array in this way.

   g_besse = new double[,]{{1,2},{3,4}} ;

This code allocates new memory for array. If you need reinitialize this array many times, you can create custom method for change array's values.

Upvotes: 2

Related Questions