How to use switch with goto case in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "abcd";

            for (int i = 0; i < s.Length; i++)
            {
                  switch (s[i])
                  {
                        case 'a':
                            Console.Write("a - not ");
                            goto case 'x';
                        case 'b':
                            Console.Write("b - not ");
                            goto case 'x';
                        case 'x':
                            Console.WriteLine("x");
                            break;
                        default:
                            Console.WriteLine("default");
                            break;
                  }
             }
         }
    }
}


/*
run:
    
a - not x
b - not x
default
default

*/

 



answered Apr 25, 2017 by avibootz

Related questions

1 answer 242 views
1 answer 288 views
2 answers 376 views
2 answers 366 views
3 answers 421 views
2 answers 348 views
3 answers 373 views
...