Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url in code not breaking build [duplicate]

Tags:

c#

During a demo I saw a piece of test code where the developer had pasted an url in the code. And when the developer build the application everything worked, but we where all very curious why the compiler accepted the url as a line.

public class Foo
{
   // Why doesn't 'http://www.foo.org' break the build?
    public void Bar()
    {
        http://www.foo.org
        Console.WriteLine("Do stuff");
    }
}

Why does the code above build? Does the compiler treat the line as a comment?

like image 656
smoksnes Avatar asked May 13 '16 06:05

smoksnes


1 Answers

If you try the exact code above, you get warning CS0164: This label has not been referenced.

The warning here offers a clear hint as to what has happened.

Pasting the URL has created a label http:, e.g. for use with goto, immediately followed by a single-line comment, //www.foo.org.

like image 64
yaakov Avatar answered Oct 05 '22 09:10

yaakov