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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With