I’m reviewing some code on the project I recently joined, and in a C# Win Forms Application for .NET 3.5 I found this:
public void foo()
{
//Normal code for function foo.
//This is at the end and it is left-indented just as I put it here.
EndPoint:
{
}
}
When I click “EndPoint/Go To Definition” it says “Cannot Navigate to Endpoint” but the project as a whole is pretty small and compiles/runs without error, so it’s not a missing reference or anything.
What is EndPoint and what is this syntax with the name : {}?
Its for
goto. See: http://msdn.microsoft.com/en-us/library/13940fs2%28VS.71%29.aspxThe syntax with the colons specifies the labels where the
gotostatement will transfer control to. You can use it in C#, but most developers tend to avoid it. Sometimes it can be useful to break out of nested loops (that’s the best I can come up with for a “legitimate” usage)Here’s a nice writeup on some of the more useful usages of
goto: http://weblogs.asp.net/stevewellens/archive/2009/06/01/why-goto-still-exists-in-c.aspxEDIT: Just to comment on the error you get about going to definition, that’s understandable. There is no “definition” source for the label. Perhaps “go to definition” on the
goto Endpoint;might jump to the label, but I’m not sure — never tried it. If your code that you have there only has theEndpoint:label but nogoto Endpoint;anywhere, then it should be safe to delete the label because (I’m assuming) it’s an unused remnant of old code.