Is goto statement supported in C#? How about Java?

Answers were Sorted based on User's Feedback



Is goto statement supported in C#? How about Java?..

Answer / ranganathkini

Yes goto is supported in C# and is not supported in Java.
They are quite handy when writing switch statements where in
moving from one case label to another. Example:

Console.Write( "Enter name of country: " );
string country = Console.ReadLine();
switch( country ) {
case "India":
Console.WriteLine( "Welcome to India" );
break;
case "USA":
Console.WriteLine( "Welcome to USA" );
break;
default:
goto case "India";
}

There also a couple of restrictions for using goto
statements in C#:

1. U cannot jump into a statement block such as a loop.
2. U cannot jump out of a class.
3. U cannot exit a finally block.

Java strongly resents the use of the goto statements and
considers it to be a bad practice for programming. In fact
some of the early Java compilers wud show a warning if the
programmer used goto in his program. The message wud be as
follows:

KeywordTest.java:4: 'goto' not supported. Duh.
You have no business programming in Java. Begin erasing Java
Software Development Kit? (Yes/No)
1 life-altering error

Tats someting i wanted to share with u guys. ;-)

Is This Answer Correct ?    2 Yes 2 No

Is goto statement supported in C#? How about Java?..

Answer / swapna

In java goto statement is not supported.
In c# also as far as i know goto statement is not supported.

Is This Answer Correct ?    3 Yes 6 No

Post New Answer

More C Sharp Interview Questions

What is use of hashtable in c#?

0 Answers  


how to access the virtual method without creating the objet for the virtual method?

1 Answers  


What is sqladapter c#?

0 Answers  


Does a class need a constructor c#?

0 Answers  


Give some examples of commonly used i/o classes?

0 Answers  






Why do we need a finally block in try catch block while handling exceptions

4 Answers   IBM,


What can I create with c#?

0 Answers  


what class is underneath the sortedlist class?

0 Answers   Siebel Systems,


What is a predicate in c#?

0 Answers  


which datatype i have to use we i need dynamic size.for eg. empname .in first row it have only five chars.but next row it have 100 chars.

3 Answers  


What are abstract classes in c#?

0 Answers  


Why do we use delegates in c#?

0 Answers  


Categories