Home Forums C# Programming Cannot implicitly convert type int to string? why? Reply To: Cannot implicitly convert type int to string? why?

#3405
msaqib
Participant

HelloYou are trying to use string type variable in your switch statement which is expecting an int type variable. Here is how you are doing

string thirdn;
switch (thirdn){
case 1:
//code
case 2:
//code
}

Now the problem is you can not use string type variable in switch statement. You could use it like


string thirdn;
switch (thirdn){
case "1":
//code
case "2":
//code
}

Or you could have use int type variable like


int thirdn;
switch (thirdn){
case 1:
//code
case 2:
//code
}