Does C# support goto statement?

48. Does C# support goto statement?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, C# supports the goto statement. The goto statement transfers the control of the program to the specified label and the label is the valid identifier and placed just before the statement from where the control is transferred.

Example:

using System;

class Program {
  public static void Main() {
    Console.WriteLine("In the main...");
    int i = 1;

    okay:
      Console.Write(i + " ");
    if (++i <= 10) {
      goto okay;
    }

  }
}

/*
Output:
In the main...
1 2 3 4 5 6 7 8 9 10 
*/

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.