Results 1 to 4 of 4

Thread: what is "fallthrough" situation in C#?

  1. #1
    Join Date
    May 2009
    Posts
    1,191

    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.

  2. #2
    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;
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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;

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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;
    
    }

Similar Threads

  1. Replies: 3
    Last Post: 10-01-2014, 10:40 AM
  2. Replies: 6
    Last Post: 18-05-2010, 12:27 AM
  3. Replies: 3
    Last Post: 25-06-2009, 03:49 AM
  4. Replies: 2
    Last Post: 24-12-2008, 05:06 PM
  5. Replies: 1
    Last Post: 06-11-2007, 02:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,282,452.09329 seconds with 17 queries