Home › Forums › C# Programming › Cannot implicitly convert type int to string? why? › Reply To: Cannot implicitly convert type int to string? why?
July 10, 2008 at 2:11 pm
#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
1 2 3 4 5 6 7 | string thirdn;<br /> switch (thirdn){<br /> case 1:<br /> //code<br /> case 2:<br /> //code<br /> } |
Now the problem is you can not use string type variable in switch statement. You could use it like
1 2 3 4 5 6 7 8 | <br /> string thirdn;<br /> switch (thirdn){<br /> case "1":<br /> //code<br /> case "2":<br /> //code<br /> } |
Or you could have use int type variable like
1 2 3 4 5 6 7 8 | <br /> int thirdn;<br /> switch (thirdn){<br /> case 1:<br /> //code<br /> case 2:<br /> //code<br /> } |