473,473 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 6719
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.