Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



what is "fallthrough" situation in C#?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-11-2009
Member
 
Join Date: May 2009
Posts: 1,144
what is "fallthrough" situation in C#?

Hi,
I am last year B.Sc.IT student.I had learn C#.In my last exam in C# paper there is question like "what is "fallthrough" situation in C#?".I had never heard this kind of term in C#.That's why I asked this question in this forum. If you have any idea about this please help me.
thanks in advanced.
Reply With Quote
  #2  
Old 25-11-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: what is "fallthrough" situation in C#?

Fallthrough is a situation that is use in switch statement to go from one case to another or go to next case. C# does not allow automatic fallthrough situation in a switch statement. You can enable this situation using goto statement. In C# if you are able to write your goto statement to go to the next case statement, then it is said that you achieve fallthrough.

Below is the example of fallthough situation:

Code:
switch ("ramesh")
{
   case "ramesh":
       Console.WriteLine ("hello ramesh");
       goto case "amit";
   case "amit":
       Console.WriteLine (" hello amit");
       break;
   default:
       break;
}
Reply With Quote
  #3  
Old 25-11-2009
Member
 
Join Date: May 2008
Posts: 1,990
Re: what is "fallthrough" situation in C#?

In other language what happened that in switch statement if your case is match then only that case is executed and you come out of the switch statement.In C# if your switch case is match then you can go to another case using fallthrough situation.Here below is the example of fallthrough situation.See how control is passed from one case to another case.


Code:
switch (1)
{
   case A:
       Console.WriteLine ("you are in case A");
       goto case B;
   case B:
       Console.WriteLine ("you are in case B");
       break;
   default:
       break;
Reply With Quote
  #4  
Old 25-11-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: what is "fallthrough" situation in C#?

fallthrough situation:fallthrough is very useful concept in C# language.You can activate fallthrough situation by using 'goto <case label>' statement. It specify you where exactly you want to go.Break statement is used to break switch statement and come out of the switch statement.
Code:
switch(value)

{

case Apple:

Console.WriteLine("In case Apple\n");

goto case Mango;

case Mango:

Console.WriteLine("In case Mango\n");

goto case banana;

case banana:

Console.WriteLine("In case banana\n");

break;

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "what is "fallthrough" situation in C#?"
Thread Thread Starter Forum Replies Last Post
can i make word stop "correcting" "for the" to "fort he" tbhanson MS Office Support 7 28-08-2010 07:49 PM
<input type="button" value="Enregistrer" onclick="location.href=../asp/PRaces.asp"> Luz Software Development 6 18-05-2010 01:27 AM
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Platebanger Vista Help 6 05-02-2008 08:24 PM
Adding commands to "Folder Options/Edit File Type/Actions" grayed-out "Edit" & "Remove" Green_XP Windows XP Support 1 06-11-2007 02:18 PM
msiexec.exe Application Error "The instruction at "0x00f33fe8" referenced memory at "0x00f33fe8". The memory could not be "written"." Edward Ray Office Setup 5 28-07-2005 01:25 AM


All times are GMT +5.5. The time now is 11:28 AM.