Multiple Namespaces in Separate File

J

Jack Li

Hi,
If I declare multiple namspaces, each in a separate file, how do I
specify their path with the "using" directives?

Say I have 2 namespaces and 1 main function, all in separate files such
as follows
=====================================
File1.cs:
namespace A
{
public class Foo
{ .... }
}
=====================================
File2.cs:
namespace B
{
public class Bar
{ .... }
}
=====================================
Application.cs:

using System;
using A;
using B;

class Greeting
{
public Foo f = new Foo ();
public Bar b = new Bar ();
static void Main()
{ ..... }
}

=====================================
using A and using B gives me this error:
The type or namespace name 'A' could not be found (are you missing a
using directive or an assembly reference?)
The type or namespace name 'B' could not be found (are you missing a
using directive or an assembly reference?)

Obviously I have not missed a "using" directive. How should I let
Application.cs know that A and B are sitting in File1.cs and File2.cs
respectively ?

I really don't want to put them one single file, as you can see a
nightmare is coming when the project span across 100 people, each with
a couple of their own namespace....

Many Many Thx
Jack
 
M

Mattias Sjögren

Obviously I have not missed a "using" directive. How should I let
Application.cs know that A and B are sitting in File1.cs and File2.cs
respectively ?

Do you compile all the source files at the same time or to separate
executables? If all are compiled to the same assembly then you
shouldn't have to do anything special. If they are compiled to
separate assemblies you must reference A.dll and B.dll (or whatever
they are called) when compiling Application.cs.


Mattias
 
J

Jack Li

thx, the truth is, Application.cs serves as the "codebehind" for an
asp.net pages.
The two namespaces define some utility functions that may be shared by
multiple pages.

Say I have 3 pages,
p1.aspx, p2.aspx, p3.aspx, each with with their codebehind C# file
f1.cs, f2.cs, f3.cs

all of the c# file use a namespace from a seperate file, which contains
some utility functions. I really don't want to define them multiple
times. Instead, I want to define them once in a single file and have
f1, f2, f3 use it.

So is it necessary to compile the utility file and have other pages
reference the DLL ?
thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C#/Mono namespaces 3
question on namespaces 7
Generic 3
Resolving ambiguous references 2
CSharp demo 3
Mismatched behaviour between regular compiler and refactoringcompiler 10
Partial interfaces 5
LinkedListLibrary 2

Top