471,327 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,327 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 1573
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by konf | last post: by
6 posts views Thread by Joachim | last post: by
2 posts views Thread by James Zhuo | last post: by
1 post views Thread by BSand0764 | last post: by
reply views Thread by rosydwin | last post: by

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.