Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi when i write following command:
C#
switch (myparam)
			{
				
				case "p1":
					this.Close();
					break;
				case "p2":
					break;
				case "p3": 
					if (mytag)
					{
						return;
					}
					myprocc1();
					
                    
			}


this error be shown after compile
Error 5 Control cannot fall through from one case label ('case "p3":') to another


thanks
Posted
Updated 25-Jan-15 18:16pm
v2
Comments
King Fisher 26-Jan-15 0:27am    
Add break; for Case 3:

You have simply forgot to add the break into the end of the case "p3". Because of that the execution would fall the the next case. To correct the situation add the break. Like
C#
switch (myparam)
{
   case "p1":
      this.Close();
      break;
   case "p2":
      break;
   case "p3":
      if (mytag)
      {
         return;
      }
      myprocc1();
      break; 
}

But in overall, I agree that you should first check the documentation for the statements you have problem with. This way you get to know the language in overall :)
 
Share this answer
 
Comments
King Fisher 26-Jan-15 0:26am    
5+ ;)
Wendelius 26-Jan-15 1:14am    
Thanks :)
jaket-cp 26-Jan-15 5:12am    
My 5 - learnt something new today :)
C# works differently than other language in switch-case fall through (interesting)
Wendelius 26-Jan-15 8:33am    
Glad to be of service
BillWoodruff 27-Jan-15 3:38am    
+5
Dude, do you intend to read some book, take some tutorial, use intellisense, read the compiler messages... or something on your own? You are falling into basic syntactical errors... one after an other...

Stop posting on every little mistake you do, and use google at least!

Start HERE[^] for example, and don't you come back until you have finisged it...
 
Share this answer
 
Comments
jaket-cp 26-Jan-15 5:13am    
Good advice, but is it a good read?
1000 odd pages to go through :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900