473,241 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

A value of an integral type expected

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.
Jun 27 '08 #1
4 6698
On Jun 4, 8:48 am, AA2e72E <AA2e...@discussions.microsoft.comwrote:
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
Jun 27 '08 #2
On Wed, 04 Jun 2008 00:48:00 -0700, AA2e72E
<AA*****@discussions.microsoft.comwrote:
I am getting this error with a switch statement: what doe it mean?
It means that the type used in the switch() statement is required to be an
"integral" type. As in "integer". As in NOT "array of integers".

The switch() statement simply does not work with complex types. Anything
that can be represented as a simple integer value is fine. Anything else
is pretty much not, with the exception of strings.

An equivalent to what it _appears_ you are doing would be this:

switch (arg1 is string ? "1" : "0" + arg2 is string ? "1" : "0")
{
case "00":
break;
case "01":
break;
// etc.
}

Now, that said...given that we're dealing with only four different
possibilities here, and given that it seems likely to me that arguments
that are actually strings are likely to be handled in similar ways to each
other, it might make more sense to just handle each argument individually.

I mean, does the code that depends on whether arg1 is a string _really_
affect how you use arg2, and vice a versa? Unless each case statement has
code that's radically different from every other case statement, I think a
switch() statement is probably not the right construct to use here.

Pete
Jun 27 '08 #3

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.
Jun 27 '08 #4
On Jun 4, 9:31 am, AA2e72E <AA2e...@discussions.microsoft.comwrote:
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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave | last post by:
Hello all, Suppose you have an unsigned integral type T. It's not one of the built-in types, but rather typedefed off of one of the built-in unsigned integral types (but we don't know which...
2
by: bdwise | last post by:
I want to do a switch statement on the value returned from getype(), but the value is not an integral type. Is there a way to do something besides gettype().ToString() and not use an if statement?
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
14
by: Geoff Jones | last post by:
Hi I'm trying to use a class that I've written in a form. Unfortunately, when I write something like: Public x As New myClass I get the compile time error: "Type Expected". Indeed, the...
18
by: u.int.32.t | last post by:
How do you suggest iterating from some size_t M down to 0? The obvious way is: for(size_t i = M+1; i > 0; --i){...} Another way is to depend on wraparound... Any suggestions?
10
by: Tomás | last post by:
When you simply want to store a number, what integral type do you use? For instance, let's say we have the following in a Poker game: struct Card { enum Suit { Hearts, Diamonds, Spades, Clubs...
2
by: Ranganath | last post by:
Hi, Why is there a restriction that only integral types can be made static constant members of a class? For e.g., class B { private: static const double K = 10; };
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.