473,473 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why does this compile with a space: this.option1 .Checked = true;

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.

Regards,
Johann Blake
Nov 16 '05 #1
3 1190
That is just the semantics of C#.
You may also do
this.option1

..Checked = true;

if you want.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Johann Blake" <jo*********@yahoo.com> wrote in message
news:d8*************************@posting.google.co m...
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.

Regards,
Johann Blake

Nov 16 '05 #2
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
Nov 16 '05 #3
Hi Johann:

I'm no expert, but here's my 2-cents' worth.

First, the short version:
No bug. Legal. My understanding is that in C# extra white space such as
space, linefeed, tab etc. is ignored. That's why you need ; to end a
statement.

Medium answer:
The . is enough to separate the object from the member. If you like, you
could even press <Enter> or <Tab>.

A bit more detail:
This gives you the freedom to format your code as you like to show
structure. This can eventually make the program easier to understand. So
it's easier firstly to get right, and secondly to revise by you when you've
forgotten how you made it or by someone else who never knew what you did.

The Microsoft IDE's source editor can help in the formatting.

Summary:
Deliberate feature to promote readability, maintainability.

"Johann Blake" 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.


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
2
by: news frontiernet.net | last post by:
I have key entered and tried to run example 4-6 from Dany Goodmans DYNAMIC HTML book, version one that is on pages 94-96. This is part of my effort to learn JavaScript. I checked each byte and...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
7
by: Clint Herron | last post by:
Howdy! I posted this question on CSharpCorner.com, but then realized I should probably post it on a more active newsgroup. This will be my only cross-post. I'm creating a game engine, and...
11
by: Brian W | last post by:
Yet another editor problem To reproduce do the following 1) Open a Webform and switch to HTML edit mode 2) Enter the Following (include spaces) This is some text before <asp:hyperlink...
13
by: moondaddy | last post by:
my understanding is that the max value of a byte is 255. Therefore, why does the following code get a compile error? byte val1 = 10; byte val2 = 23; byte ttl; ttl = val1 + val2; //this line...
21
by: Peter Olcott | last post by:
I got the previous alias to std::vector working, and found that it takes up the space of a pointer. I want to find a way to do an alias to a std::vector that does not take up any space. Is there...
5
by: techvaibhav | last post by:
Hello everyone i am stuck in a very annoying problem.Hope you guys help me fix this out. I am displaying questions form a Question database along with its options. Options can be controlled by...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.