Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid expression term '{' (Declaring array outside switch statement)

Tags:

arrays

c#

I've started an algorithm for a program, and I've declared the array in method itself. However, when I reference the array inside the switch statement I get repetitive errors: Invalid expression term '{' and '{' expected and ';' expected Below is the code:

algorithm()
{
code .....
int[] interval;
more code....
switch (int.parse(lbl2.text))
    {
    case 1:
        sInterval = {10, 20, 30, 40};
        break;
    case 2:
        sInterval = { 50, 60, 70, 80};
        break;
    }
}

How do you fix this problem?

like image 250
Michael D Avatar asked Apr 26 '26 13:04

Michael D


1 Answers

The correct syntax is new int[]{10, 20, 30, 40}

like image 111
Fábio Junqueira Avatar answered Apr 29 '26 01:04

Fábio Junqueira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!