473,396 Members | 1,599 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.

Multiple Namespaces in Separate File

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

Jun 1 '06 #1
2 3550
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 1 '06 #2
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

Mattias Sjögren wrote:
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Jun 2 '06 #3

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...
5
by: EMonaco | last post by:
All, I have a simple C# window app under MyApp namespace it has a class Form1. I've added another class .cs file. Now this class I want to share with many projects, so I figured I'd change this...
7
by: Thomas Koch | last post by:
Hi - does anyone know if it is possible to document namespaces in C# using the XML documentation tags or something similar? Cheers Thomas Koch
2
by: sandman | last post by:
I'm writing a conversion utility to move data from ver 1 of my C# WinForms app (Access database) to ver 2 (SQL server). I realized that I have most of the tools I need already written (read and...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
1
by: icfai | last post by:
hi friends.... I have got a problem regarding loading of multiple assemblies, actually its required for an editor which implements the intellisenseas in vb or dotnet. for that it is required to...
5
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
9
by: PetrH | last post by:
The problem I have is basically the same as 'greentype' mentions at <Link Removed> I'm sharing variables through namespaces and a problem arises when I try to put my function definitions into a...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.