473,624 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3562
>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
3033
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 a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
5
1291
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 class.cs file from namespace MyApp Class MyClass
7
7268
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
1638
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 write data) and they are in separate .NET projects. But when I wrote ver 2, I kept all the namespaces and class names the same. I've gone thru and renamed the output dll's in ver 2 so I can reference both sets of libraries in my conversion project...
9
2764
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 wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
6
2067
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 DeviceManager which is only interested in CD/DVD devices. I want to get the list of CD/DVD devices and "be informed when a disc inserted into a device". I am developing this on Linux. So, I used HAL API and read some system (actually /proc) files to gather...
1
1985
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 load that assembly whose sub-classes are required to be loaded into the list box after pressing dot. for example in the code given below i have given the path of System.dll assembly file, now all the sub class of System.Data are automatically...
5
1595
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 handling internal information. Than I have web service, that also uses the same classes (I included the file as linked external resource). I included this web service as web reference and used name wsWeb. When I am trying to call the web...
9
12764
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 separate file. Consider the following example, where I want to pass variable 'i', defined in the main code, to the function a(): ------------------------------ *** nn.h: ***
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7170
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.