473,396 Members | 1,927 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,396 software developers and data experts.

Namespaces being stupid

I've made some controls that have namespaces and I have trouble with
the "using namespace" line, it doesn't do anything. Here's what's
going on:

1). I have a class like this:

namespace N1.N2
{
class A{};
}

2). I reference the project with N1.N2 from another project's file
where I want to use my class I have:

using N1;
using N1.N2;

namespace N3
{
// Inside the code somewhere ...
N2.A test = new N2.A(); // This line does not work
N1.N2.A test = new N1.N2.A(); // This DOES work

Why can't I make use of the "using namespace" line to shorten my code?
I don't want to have to write out all the N1.N2.xxxx stuff, it's
annoying and makes my code look messy. There are not naming conflicts
with other namespaces.

Help please!

Thanks!
Nov 15 '05 #1
6 1336
"Justin" <jh***@stanford.edu> wrote in message
news:67**************************@posting.google.c om...
I've made some controls that have namespaces and I have trouble with
the "using namespace" line, it doesn't do anything. Here's what's
going on:

1). I have a class like this:

namespace N1.N2
{
class A{};
}

2). I reference the project with N1.N2 from another project's file
where I want to use my class I have:

using N1;
using N1.N2;

namespace N3
{
// Inside the code somewhere ...
N2.A test = new N2.A(); // This line does not work
N1.N2.A test = new N1.N2.A(); // This DOES work

Why can't I make use of the "using namespace" line to shorten my code?
I don't want to have to write out all the N1.N2.xxxx stuff, it's
annoying and makes my code look messy. There are not naming conflicts
with other namespaces.


Hi Justin,

A using statement only allows you to reference types, not nested namespaces.
The dot operator in the N1.N2 namespace declaration makes N2 a nested
namespace. If you want a shortcut, you could try an alias:

using aliasN2 = N1.N2;

aliasN2.A test = new aliasN2.A();

Joe
--
http://www.csharp-station.com
Nov 15 '05 #2
"Justin" <jh***@stanford.edu> wrote in message
news:67**************************@posting.google.c om...
I've made some controls that have namespaces and I have trouble with
the "using namespace" line, it doesn't do anything. Here's what's
going on:

1). I have a class like this:

namespace N1.N2
{
class A{};
}

2). I reference the project with N1.N2 from another project's file
where I want to use my class I have:

using N1;
using N1.N2;

namespace N3
{
// Inside the code somewhere ...
N2.A test = new N2.A(); // This line does not work
N1.N2.A test = new N1.N2.A(); // This DOES work

Why can't I make use of the "using namespace" line to shorten my code?
I don't want to have to write out all the N1.N2.xxxx stuff, it's
annoying and makes my code look messy. There are not naming conflicts
with other namespaces.


Hi Justin,

A using statement only allows you to reference types, not nested namespaces.
The dot operator in the N1.N2 namespace declaration makes N2 a nested
namespace. If you want a shortcut, you could try an alias:

using aliasN2 = N1.N2;

aliasN2.A test = new aliasN2.A();

Joe
--
http://www.csharp-station.com
Nov 15 '05 #3
jh***@stanford.edu (Justin) wrote in
news:67**************************@posting.google.c om:
I've made some controls that have namespaces and I have trouble
with the "using namespace" line, it doesn't do anything. Here's
what's going on:

1). I have a class like this:

namespace N1.N2
{
class A{};
}

2). I reference the project with N1.N2 from another project's
file where I want to use my class I have:

using N1;
using N1.N2;

namespace N3
{
// Inside the code somewhere ...
N2.A test = new N2.A(); // This line does not work
N1.N2.A test = new N1.N2.A(); // This DOES work

Why can't I make use of the "using namespace" line to shorten my
code?
I don't want to have to write out all the N1.N2.xxxx stuff,
it's
annoying and makes my code look messy. There are not naming
conflicts with other namespaces.


Justin,

I don't think you need the "using N1" statement. All you should need
is:

using N1.N2;

namespace N3
{
... inside a class somewhere ...
A test = new A();
}

"using" directives in C# are very simple when compared to languages
like Java and Python. There are no wildcards and the namespace name
has no dependency upon the folder the .cs file is stored in. If
you're familiar with Delphi, C# "using" directives are very similar
to Delphi's "uses" clause.

The "dot" (.) in an individual namespace name has no special
significance, other than to separate words in the namespace name.

See the docs for more info and examples:

http://msdn.microsoft.com/library/de...l=/library/en-
us/csref/html/vclrfNamespaces.asp

or

http://tinyurl.com/ptsq
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 15 '05 #4
jh***@stanford.edu (Justin) wrote in
news:67**************************@posting.google.c om:
I've made some controls that have namespaces and I have trouble
with the "using namespace" line, it doesn't do anything. Here's
what's going on:

1). I have a class like this:

namespace N1.N2
{
class A{};
}

2). I reference the project with N1.N2 from another project's
file where I want to use my class I have:

using N1;
using N1.N2;

namespace N3
{
// Inside the code somewhere ...
N2.A test = new N2.A(); // This line does not work
N1.N2.A test = new N1.N2.A(); // This DOES work

Why can't I make use of the "using namespace" line to shorten my
code?
I don't want to have to write out all the N1.N2.xxxx stuff,
it's
annoying and makes my code look messy. There are not naming
conflicts with other namespaces.


Justin,

I don't think you need the "using N1" statement. All you should need
is:

using N1.N2;

namespace N3
{
... inside a class somewhere ...
A test = new A();
}

"using" directives in C# are very simple when compared to languages
like Java and Python. There are no wildcards and the namespace name
has no dependency upon the folder the .cs file is stored in. If
you're familiar with Delphi, C# "using" directives are very similar
to Delphi's "uses" clause.

The "dot" (.) in an individual namespace name has no special
significance, other than to separate words in the namespace name.

See the docs for more info and examples:

http://msdn.microsoft.com/library/de...l=/library/en-
us/csref/html/vclrfNamespaces.asp

or

http://tinyurl.com/ptsq
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 15 '05 #5
On Sun, 5 Oct 2003 18:59:37 -0600, "Joe Mayo"
<jm***@ddiieessppaammeerrssddiiee.com> wrote:

A using statement only allows you to reference types, not nested namespaces.
The dot operator in the N1.N2 namespace declaration makes N2 a nested
namespace. If you want a shortcut, you could try an alias:

using aliasN2 = N1.N2;

aliasN2.A test = new aliasN2.A();


Actually, his problem is that the dot in .net namespaces is not really
a nesting operator. It is not safe to assume that the N1.N2 namespace
is inside of the N1 namespace.

Nov 15 '05 #6
"Jekke, Just Jekke" <je***@REMOVEALLinsidejoke.tvCAPS> wrote in message
news:6s********************************@4ax.com...
On Sun, 5 Oct 2003 18:59:37 -0600, "Joe Mayo"
<jm***@ddiieessppaammeerrssddiiee.com> wrote:

A using statement only allows you to reference types, not nested namespaces.The dot operator in the N1.N2 namespace declaration makes N2 a nested
namespace. If you want a shortcut, you could try an alias:

using aliasN2 = N1.N2;

aliasN2.A test = new aliasN2.A();


Actually, his problem is that the dot in .net namespaces is not really
a nesting operator. It is not safe to assume that the N1.N2 namespace
is inside of the N1 namespace.


That is not what I said. N2 is nested in N1. Looking at the original
poster's code:

namespace N1.N2
{
class A{};
}

is semantically equivalent to:

namespace N1
{
namespace N2
{
class A{};
}
}

according to the C# Specification:

http://www.jaggersoft.com/csharp_standard/16.2.htm

Joe
--
http://www.csharp-station.com
Nov 15 '05 #7

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

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
24
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
4
by: Sean Quinn | last post by:
Recently I've come across an oddity in .NET, going back to a Managed C++ implementation for GUIs since I never really learned how to code in MFC. Any way, I attempted to put some standard code I...
0
by: Justin | last post by:
I've made some controls that have namespaces and I have trouble with the "using namespace" line, it doesn't do anything. Here's what's going on: 1). I have a class like this: namespace N1.N2...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
7
by: Paul | last post by:
Hello, I'm coming from a PHP background and am working on a large-scale VB.NET project. One of the cornerstones of this project is a reusable form class, to standardize our web forms. My goal...
2
by: Lore Leunoeg | last post by:
Hello I'm using c# XmlDocument class to add new XHTML-Nodes to my website. Unfortunately XmlDocument always adds an unwanted empty namespace attribute xmlns="" to every new Element. These empty...
7
by: Peter Kirk | last post by:
Hi, there is a logging service called "log4net". It uses namespaces such as "log4net" and "log4net.Appender". If I am writing my own software, would it be considered bad style to use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.