A value of an integral type expected

  • Thread starter Thread starter AA2e72E
  • Start date Start date
A

AA2e72E

I am getting this error with a switch statement: what doe it mean?

int[] res = new int[] {Convert.ToInt32(arg1 is string[]),
Convert.ToInt32(arg2 is string[])};

switch (res)
{
case new int[]{0,0}:
{
............
}
case new int[]{0,1}:
{
....
}
}

How can I resolve this?

Thanks for your help.
 
I am getting this error with a switch statement: what doe it mean?

switch/case only applies to integral types (including char).

Why are you converting booleans to ints anyway? Are you just trying to
do four different things depending on whether arg1 and arg2 are string
arrays or not? If so, I'd just use if/else if/else if/else. You
*could* do some bitshifting to get a 0-3 value and then switch on
that, but I don't think it would be as readable.

Jon
 
Thanks for yout help.

"You *could* do some bitshifting to get a 0-3 value and then switch on
that"

How do you do that?

That's what I started out with, get to values 0,1,2,3: could not figure it
out.

Thanks also, Peter.
 
Thanks for yout help.

"You *could* do some bitshifting to get a 0-3 value and then switch on
that"

How do you do that?

That's what I started out with, get to values 0,1,2,3: could not figure it
out.

int nasty = (arg1 is string[] ? 2 : 0) | (arg2 is string[] ? 1 : 0);

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top