473,382 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1188
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.