Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Problems with double[] myArray and If statement

Hello I don’t know why my code does not work, here the extract

        bool flag = true;
        double[] dblColsBis = { 60, 90, 90, 90, 90 };

        double[] dblRowsBis = { 20 };


        if (flag)
        {
             dblColsBis = { 120, 60, 60, 60, 60 };

             dblRowsBis = { 15 };
        }

Can you help me please?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It really helps when you write what "does not work" mean, but in this case I can see what is wrong.

This syntax:

double[] dblColsBis = { 60, 90, 90, 90, 90 };

is only available when you declare the variable, in particular, the initialization syntax there.

If you want to assign a new array instance to that variable, you have to also construct the new array instance, like the following adjusted copy of your code:

bool flag = true;
double[] dblColsBis = { 60, 90, 90, 90, 90 };

double[] dblRowsBis = { 20 };


if (flag)
{
    dblColsBis = new double[] { 120, 60, 60, 60, 60 };

    dblRowsBis = new double[] { 15 };
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading