472,958 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Compilation Error

Newbie using VC# Express.....

Part the First
========
Can some one tell me why Example 1 compiles and Example 2 does not...

Example 1
------------

using System;
namespace System.Data
{
partial class Console
{
public int GetHeight()
{
int i = System.Console.BufferHeight;
return i;
}
}
}

Example 2
------------

using System;
namespace System
{
partial class Console
{
public int GetHeight()
{
int i = System.Console.BufferHeight;
return i;
}
}
}

The error is: Error 2 'System.Console' does not contain a definition for
'BufferHeight'

In fact I seem to be able to use any namespace except "System".

Part the Second
==========

Why does the following fail to compile...

using System;
using System.Data;
namespace ClassLibrary1
{
public class Class1 { }
}
namespace System.Data
{
public partial class DataGrid
{
public static void AnyCall(DataGrid pGrid)
{
DataGrid dg = new DataGrid();
BindingContext bc = dg.BindingContext; // this line generates
the errors
}
}
}

The errors are:

Error 1 The type or namespace name 'BindingContext' could not be found (are
you missing a using directive or an assembly reference?)
Error 2 'ClassLibrary1.DataGrid' does not contain a definition for
'BindingContext'

So it can see a DataGrid, but not the properties of it.

It is obvious I do not understand namespaces / accessibility of references....

--
Paul Cotter
Dec 18 '05 #1
1 1652
Both of your problems stem from your creation of namespaces that you are
attempting to use. The using directive informs the compiler that you are
using members of the namespace indicated. When you create a new namespace of
the same name, the code scoped within that new namespace assumes that you
are referring to members of the namespace in which they are created. Since
the members being referenced are in the other namespace outside of that
namespace, having the same name, they do not exist in the current namespace
context, and are not found.

NameSpaces are a device for uniquely identifying members within those
namespaces. Think of a namespace as the "city" part of an address. The name
of the member is like the street address. Now, if you are in Chicago, and
someone says, "where is Broadway?" you simply point to the location of
Broadway in the city you are already in. But if you were outside of Chicago,
and someone said "Where is Broadway?" your first thought would be "Broadway
in what city?" It could be in Chicago, New York, or any of thousands of
cities having a street named "Broadway." Now, let's say you were back in
Chicago, and someone asked you "Where is BroadWay in New York City?" You
wouldn't have to be in New York to know what street they were referring to.
They gave you the NameSpace of the reference.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Paulustrious" <msdn_whoisat_paulcotter.com> wrote in message
news:C5**********************************@microsof t.com...
Newbie using VC# Express.....

Part the First
========
Can some one tell me why Example 1 compiles and Example 2 does not...

Example 1
------------

using System;
namespace System.Data
{
partial class Console
{
public int GetHeight()
{
int i = System.Console.BufferHeight;
return i;
}
}
}

Example 2
------------

using System;
namespace System
{
partial class Console
{
public int GetHeight()
{
int i = System.Console.BufferHeight;
return i;
}
}
}

The error is: Error 2 'System.Console' does not contain a definition for
'BufferHeight'

In fact I seem to be able to use any namespace except "System".

Part the Second
==========

Why does the following fail to compile...

using System;
using System.Data;
namespace ClassLibrary1
{
public class Class1 { }
}
namespace System.Data
{
public partial class DataGrid
{
public static void AnyCall(DataGrid pGrid)
{
DataGrid dg = new DataGrid();
BindingContext bc = dg.BindingContext; // this line generates
the errors
}
}
}

The errors are:

Error 1 The type or namespace name 'BindingContext' could not be found
(are
you missing a using directive or an assembly reference?)
Error 2 'ClassLibrary1.DataGrid' does not contain a definition for
'BindingContext'

So it can see a DataGrid, but not the properties of it.

It is obvious I do not understand namespaces / accessibility of
references....

--
Paul Cotter

Dec 18 '05 #2

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

Similar topics

4
by: konf | last post by:
Hallo, I tried to compile PGSQL 7.4 and I got error (durring make): ar: command not found What is it? Whe I can found it? I have: $ uname -a SunOS ... 5.8 Generic_108528-03 sun4u sparc...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
6
by: Joachim | last post by:
I made some project changes (which seems it doesn't help if I undo) which have created compilation error: " Server Error in '/PCSWebApp1' Application....
2
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a while...
0
by: James Zhuo | last post by:
hi all I changed the name of the class LoginPage to a different name "LoginPageOne" But the same error gets generated with the Wiliam.Request.LoginPageOne. That pretty much leaves me clueless...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
6
by: Plat | last post by:
I've Googled this for a while, to no avail. Hopefully someone can help me. Maybe I'm using the wrong terminology. Here's the scoop! Let's say I've got a simple *.ASPX page that has a syntax...
3
by: Robert | last post by:
I have a number of web projects converted from 1.1 to 2.0 in VS2005. I am methodically seeing the error below: The element 'compilation' has invalid child element 'compilers'. List of...
0
by: Stimp | last post by:
I've created an aspx page called HistoryManage.aspx. The page works fine on my local machine but when I load it off the web I get the following strange error... Compilation Error...
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.