C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Use of goto statement in C#


Posted Date: 23 Apr 2008    Resource Type: Articles    Category: .NET Framework

Posted By: VijayKumar Reddy M       Member Level: Gold
Rating:     Points: 5





The goto statement is used when you need to jump to a particular code segment.

It’s similar to the goto statement in visual basic or C++.

In the following code, if an item of array is found, the control goes to the level found and skips all code before that.

Most programmers avoid using the goto statement, but you may find a rare need for it. One such occasion is the use of fall-through on a switch statement.

Fall- thought is the ability for the control flow to fall from one case statement directly into another by leaving out the break statement.

In C#, fall-though in a switch statement is not allowed as it was in C++. However, if you explicitly tell the switch statement to go to the next label, it will perform a jump to the next case, essentially carrying out the same function as a fall-through. Note that when using a go to in a case statement, you don’t have to provide a break (in all other cases, a break statement is mandatory). in this is bill” and “sometimes I’m called William” are displayed on the screen:

 
Console.WriteLine("What is your name? ");
string name = Console.ReadLine();
switch(name)
{
case "Bill":
Console.WriteLine("My name is Bill.");
goto case "William";
case "William":
Console.WriteLine("Sometimes I’m called William.");
break;
case "Anne":
Console.WriteLine("My name is Anne. ");
break;
default:
break;
}







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Use  .  Goto  .  Code  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Constants
Previous Resource: Organize your "using" statements
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use