473,320 Members | 2,071 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,320 software developers and data experts.

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 1555
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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.