Johann Blake <jo*********@yahoo.com> wrote:
Is this a bug in the C# compiler when it parses code, or is there a
legitimate reason why the following code is legal. If so, explain why.
On a form, add an option button (radio button). Call it option1.
In code behind the form, simply write this line of code (make sure to
include the space after the word option1 and the dot:
this.option1 .Checked = true;
This compiles on my machine. Why? What makes using a space legitimate.
Here's a somewhat simpler example:
using System;
public class Test
{
string x = "hello";
public static void Main()
{
Test t = new Test();
Console.WriteLine(t.x .Length);
}
}
As for the validity - I'm not terribly hot on the details here, but the
spec does say:
<quote>
The lexical processing of a C# source file consists of reducing the
file into a sequence of tokens which becomes the input to the syntactic
analysis. Line terminators, white space, and comments can serve to
separate tokens, and pre-processing directives can cause sections of
the source file to be skipped, but otherwise these lexical elements
have no impact on the syntactic structure of a C# program.
</quote>
I guess in this the tokens here are "t" "." "x" "." and "Length". Note
that you can put them on different lines if you like, too, and even put
comments in the middle:
Console.WriteLine (t