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

Home Posts Topics Members FAQ

Why does this compile?

Maybe I don't know all the c# quirks, but the code below should be compiling, but it does.  See the bolded code at the bottom.

using System;

namespace ConsoleApplication19
{
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            Child child = new Child();
            Console.WriteLine(child.SomeVariable.ToStrin g());
        }
    }

    public class MyBase
    {
        public int SomeVariable;
    }

    public class Child : MyBase
    {
        public Child()
        {
            base.SomeVariable = 1;
            
            // why in the world does this compile???
            // note the space between the base and .SomeVariable
            base .SomeVariable = 2;    

        }
    }
}

Oct 4 '06 #1
11 1557
Frank Rizzo <no**@none.comwrote:
[-- text/html, encoding 7bit, charset: ISO-8859-1, 44 lines --]
I don't know, as you posted HTML in a text newsgroup. Please repost you
question in a format appropriate to the forum.

Thank you.

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Oct 4 '06 #2
Frank,

There is nothing in the specification that says that the period has to
come as the character right after the expression and before the
property/method. You can have as many spaces as you want.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.comwrote in message
news:OU****************@TK2MSFTNGP06.phx.gbl...
Maybe I don't know all the c# quirks, but the code below should be
compiling, but it does. See the bolded code at the bottom.

using System;

namespace ConsoleApplication19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLine(child.SomeVariable.ToString());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariable = 1;

// why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;
}
}
}
Oct 4 '06 #3
Thomas T. Veldhouse wrote:
Frank Rizzo <no**@none.comwrote:
>[-- text/html, encoding 7bit, charset: ISO-8859-1, 44 lines --]

I don't know, as you posted HTML in a text newsgroup. Please repost you
question in a format appropriate to the forum.
Sorry. I was having line overruns, which is why I posted it in html.
Here is the fixed up version.

using System;

namespace ConsoleApplication19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLine(child.SomeVariable.ToString());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariable = 1;

// why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;
}
}
}
>
Thank you.
Oct 4 '06 #4
"Frank Rizzo" <no**@none.comwrote in message
news:ec****************@TK2MSFTNGP03.phx.gbl...
base.SomeVariable = 1;

// why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;
Why wouldn't it compile? Are you attributing some mystical significance to
the white space...?

Because C# certainly doesn't...
Oct 4 '06 #5
Frank Rizzo <no**@none.comwrote:
Thomas T. Veldhouse wrote:
Frank Rizzo <no**@none.comwrote:
[-- text/html, encoding 7bit, charset: ISO-8859-1, 44 lines --]
I don't know, as you posted HTML in a text newsgroup. Please repost you
question in a format appropriate to the forum.

Sorry. I was having line overruns, which is why I posted it in html.
Here is the fixed up version.
<snip>
// why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;
Whitespace like that is fine. It's not uncommon to see:

x.DoSomething()
.DoSomethingElse()
.AndSomethingElse()

In particular, that's often seen with strings:

x = x.Trim()
.Replace ("\r", "\\r")
.Replace ("\n", "\\n");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 4 '06 #6
Jon Skeet [C# MVP] wrote:
Frank Rizzo <no**@none.comwrote:
>Thomas T. Veldhouse wrote:
>>Frank Rizzo <no**@none.comwrote:
[-- text/html, encoding 7bit, charset: ISO-8859-1, 44 lines --]

I don't know, as you posted HTML in a text newsgroup. Please repost you
question in a format appropriate to the forum.
Sorry. I was having line overruns, which is why I posted it in html.
Here is the fixed up version.

<snip>
> // why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;

Whitespace like that is fine. It's not uncommon to see:

x.DoSomething()
.DoSomethingElse()
.AndSomethingElse()
This doesn't compile on my box.
>
In particular, that's often seen with strings:

x = x.Trim()
.Replace ("\r", "\\r")
.Replace ("\n", "\\n");
This does.
>
Oct 4 '06 #7
Frank Rizzo wrote:
Jon Skeet [C# MVP] wrote:
>Frank Rizzo <no**@none.comwrote:
>>Thomas T. Veldhouse wrote:
Frank Rizzo <no**@none.comwrote:
>Whitespace like that is fine. It's not uncommon to see:

x.DoSomething()
.DoSomethingElse()
.AndSomethingElse()

This doesn't compile on my box.
Never mind, I misunderstood you. It, of course, compiles just fine.
Oct 4 '06 #8
Er.....who cares? The fact is it does, at a guess the compiler reads the
line and looks for the next character finds a '.' reads it as a combined
line and sees no issues.

i cant believe you are wasting your own time posting this and anybody elses
to ask such a question?

"Frank Rizzo" <no**@none.comwrote in message
news:OU****************@TK2MSFTNGP06.phx.gbl...
Maybe I don't know all the c# quirks, but the code below should be
compiling, but it does. See the bolded code at the bottom.

using System;

namespace ConsoleApplication19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLine(child.SomeVariable.ToString());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariable = 1;

// why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;
}
}
}
Oct 5 '06 #9

Daniel wrote:
Er.....who cares? The fact is it does, at a guess the compiler reads the
line and looks for the next character finds a '.' reads it as a combined
line and sees no issues.

i cant believe you are wasting your own time posting this and anybody elses
to ask such a question?

"Frank Rizzo" <no**@none.comwrote in message
news:OU****************@TK2MSFTNGP06.phx.gbl...
Maybe I don't know all the c# quirks, but the code below should be
compiling, but it does. See the bolded code at the bottom.

using System;

namespace ConsoleApplication19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLine(child.SomeVariable.ToString());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariable = 1;

// why in the world does this compile???
// note the space between the base and .SomeVariable
base .SomeVariable = 2;
}
}
}
That's a bit snide. Any developer who didn't know that may be saved
time debugging someone elses code who did know it just by reading this
thread. Second any curiosity is good and should be encouraged. Third,
this works in C# but not in VB.net so for anyone converting from one to
the other, it would be confusing.
If I had to recruit either you or the OP I'd go with the OP simply
because he's curious and seeks a deeper understanding of his subject
which will serve him well in the future.

Oct 5 '06 #10
Daniel wrote:
i cant believe you are wasting your own time posting this and anybody elses
to ask such a question?
I can't believe you are wasting your own time and everybody elses
answering such a dumb question.
Oct 5 '06 #11
jen

DeveloperX wrote:
If I had to recruit either you or the OP I'd go with the OP simply
because he's curious and seeks a deeper understanding of his subject
which will serve him well in the future.
i totally agree. i know that's what we look for.

cheers...

--
estroJen

Oct 5 '06 #12

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

Similar topics

2
14140
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...
8
4356
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
4
1515
by: Alex Vinokur | last post by:
Compiler GNU gpp.exe (GCC) 3.4.1 Foo(300) = Foo(500); // Foo(300) is const. Why does a compiler compile that? ------ foo.cpp ------ struct Foo { explicit Foo(int) {}
5
13999
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
13
4996
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
9
2446
by: ziman137 | last post by:
Hi all, The results from following codes got me a bit confused. #include <stdio.h> #include <iostream> using namespace std; struct A {
13
3512
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
55
6149
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
11
2681
by: MonkeeSage | last post by:
A quick question about how python parses a file into compiled bytecode. Does it parse the whole file into AST first and then compile the AST, or does it build and compile the AST on the fly as it...
5
3867
by: Jeff | last post by:
hi asp.net 2.0 I get this compile error: 'Image' does not contain a definition for 'ImageUrl' Image image = (Image)e.Item.FindControl("img"); image.ImageUrl = "~/image.png";
0
7100
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
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
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
7175
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...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7330
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
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
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.