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/