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

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,187
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
Member
 
Join Date: Apr 2008
Posts: 1,948
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: 2,008
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
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Tags: , , , ,



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
msiexec.exe Application Error "The instruction at "0x00f33fe8" referenced memory at "0x00f33fe8". The memory could not be "written"." haritable Office Setup 3 10-01-2014 10:40 AM
<input type="button" value="Enregistrer" onclick="location.href=../asp/PRaces.asp"> Luz Software Development 6 18-05-2010 01:27 AM
Power Mgt: "Turn off monitor" "Never" always reverts to "After 20 mins" akbar Windows XP Support 3 25-06-2009 04:49 AM
"The instruction at "0x77fcaff8" referenced memory at "0x00000000". The memory could not be "written". maketu Window 2000 Help 2 24-12-2008 05:06 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


All times are GMT +5.5. The time now is 10:53 PM.