Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch case giving me an error

I have the following type of code:

String strGroup = Request.QueryString["group"];

switch(strGroup.ToString){
    case "Clients":
        // do something here
        break;
    case "Addresses":
        // do something here
    break;
    case "Matters":
        // do something here
    break;
    case "Individuals":
        // do something here
     break;
    case "Organisations":
        // do something here
    break;
    default:
        break;
}

But it's giving the following error:

A value of an integral type expected for switch(strGroup.ToString){

like image 723
oshirowanen Avatar asked Feb 16 '26 13:02

oshirowanen


2 Answers

Change it to this:

switch(strGroup.ToString())

ToString() is a method, not a property. Therefore, you need to have the empty parenthesis.

Since strGroup is already a string, can't you just do the following and avoid a redundant call to .ToString()?

switch(strGroup)
like image 42
Malice Avatar answered Feb 18 '26 01:02

Malice



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!