473,785 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ 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 ConsoleApplicat ion19
{
    class Class1
    {
     &nb sp;  [STAThread]
     &nb sp;  static void Main(string[] args)
     &nb sp;  {
     &nb sp;   &nb sp;  Child child = new Child();
     &nb sp;   &nb sp;  Console.W riteLine(child. SomeVariable.To String());
     &nb sp;  }
    }

    public class MyBase
    {
     &nb sp;  public int SomeVariable;
    }

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

     &nb sp;  }
    }
}

Oct 4 '06 #1
11 1587
Frank Rizzo <no**@none.comw rote:
[-- 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.co m

"Frank Rizzo" <no**@none.comw rote in message
news:OU******** ********@TK2MSF TNGP06.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 ConsoleApplicat ion19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLi ne(child.SomeVa riable.ToString ());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariab le = 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.comw rote:
>[-- 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 ConsoleApplicat ion19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLi ne(child.SomeVa riable.ToString ());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariab le = 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.comw rote in message
news:ec******** ********@TK2MSF TNGP03.phx.gbl. ..
base.SomeVariab le = 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.comw rote:
Thomas T. Veldhouse wrote:
Frank Rizzo <no**@none.comw rote:
[-- 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()
.DoSomethingEls e()
.AndSomethingEl se()

In particular, that's often seen with strings:

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

--
Jon Skeet - <sk***@pobox.co m>
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.comw rote:
>Thomas T. Veldhouse wrote:
>>Frank Rizzo <no**@none.comw rote:
[-- 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()
.DoSomethingEls e()
.AndSomethingEl se()
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.comw rote:
>>Thomas T. Veldhouse wrote:
Frank Rizzo <no**@none.comw rote:
>Whitespace like that is fine. It's not uncommon to see:

x.DoSomething()
.DoSomethingEls e()
.AndSomethingEl se()

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.comw rote in message
news:OU******** ********@TK2MSF TNGP06.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 ConsoleApplicat ion19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLi ne(child.SomeVa riable.ToString ());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariab le = 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.comw rote in message
news:OU******** ********@TK2MSF TNGP06.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 ConsoleApplicat ion19
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Child child = new Child();
Console.WriteLi ne(child.SomeVa riable.ToString ());
}
}

public class MyBase
{
public int SomeVariable;
}

public class Child : MyBase
{
public Child()
{
base.SomeVariab le = 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

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

Similar topics

2
14169
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 Smarty-2.6.7.tar.gz on a system running WindowsXP SP2. Apache and PHP tested out fine. After adding Smarty, I ran the following http://localhost/testphp.php
8
4376
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 somebody explain it to me? I am using MSVC 6.0. Thanks a lot,
4
1529
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
14038
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 VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources... Updating references...
13
5058
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
2473
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
3561
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 some javascript code that calls window.open. I pass the resource url of page B to Page A's window.open call. Page B is then loaded and executed but none of the server-side code is rendered. If I view the source of the page, the code (and page...
55
6249
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 C# in some way? Or maybe no, because it is similar to a global variable (with its scope restricted) which C# is dead against? Zytan
11
2704
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 reads expressions? (If the former case, why can't functions be called before their definitions?) Thanks, Jordan
5
3890
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
9483
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5386
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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 we have to send another system
3
2887
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.