473,516 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Namespaces within Visual Studio IDE

Does anyone know how to incorporate classes with different namespaces within
a project? I have two classes with the same name but different namespace.
When I try to add the the second class of the same name the Visual Studio
NET IDE blocks my attempt and asks whether I want to overwrite the first
class. Which I do not want to do.

Compiling is fine outside the IDE.


Nov 15 '05 #1
4 5205
Hey,
I do not think this is possible, because you have 2 files with the same name
in the same directory. The namespace is only of importance in the file
itself. So rename the file, or put it in a subdirectory.

Greetz,
-- Rob.

Jan Michalski wrote:
Does anyone know how to incorporate classes with different namespaces
within a project? I have two classes with the same name but different
namespace. When I try to add the the second class of the same name
the Visual Studio NET IDE blocks my attempt and asks whether I want
to overwrite the first class. Which I do not want to do.

Compiling is fine outside the IDE.

Nov 15 '05 #2
Dear Rob,
Thanks for responding to this.
I have a C# file which contains the main function and two classes with the
same name within that same file. The classes have different namespaces. This
file and another associated with it compile outside the Visual Studio IDE. I
could not figure out how that file could be accommodated within the Visual
Studio NET IDE. I checked through the documentation but could not find
anything that would get me on the right track.

I suppose what I am interested in is how I can incorporate code from
different namespaces into my code. Within java this is easily done in the
various IDEs. But with Visual Studio IDE I cannot quite figure this out.

Regards,
Jan

"Rob Tillie" <Ro********@student.tul.edu> wrote in message
news:Ox*************@TK2MSFTNGP10.phx.gbl...
Hey,
I do not think this is possible, because you have 2 files with the same name in the same directory. The namespace is only of importance in the file
itself. So rename the file, or put it in a subdirectory.

Greetz,
-- Rob.

Jan Michalski wrote:
Does anyone know how to incorporate classes with different namespaces
within a project? I have two classes with the same name but different
namespace. When I try to add the the second class of the same name
the Visual Studio NET IDE blocks my attempt and asks whether I want
to overwrite the first class. Which I do not want to do.

Compiling is fine outside the IDE.


Nov 15 '05 #3
Dear Michael,

The file structure I have is the same as yours.

Can you briefly outline how you incorporate this file into your
project.When I create my project it automatically creates a namespace with
the same name as the project name. And I cannot see how to incorporate
further namespaces. I have tried to add two classes with the same name but
different namespaces. And then the IDE protests. Clearly this approach must
be incorrect. How do you do it?

Regards,
Jan

"Michael Mayer" <mr*****@charter.net> wrote in message
news:uC**************@TK2MSFTNGP10.phx.gbl...
"Jan Michalski" wrote:
<snip>
I have a C# file which contains the main function and two classes

with the
same name within that same file. The classes have different

namespaces. This
file and another associated with it compile outside the Visual

Studio IDE. I
could not figure out how that file could be accommodated within the

Visual
Studio NET IDE. I checked through the documentation but could not

find
anything that would get me on the right track.

<snip>

The following compiles just fine in my VS.NET 2002 Two classes both
named Class1. Can you post an example that doesn't work?
-mike
********* all in Class1.cs **********

using System;

namespace Namespace1
{
class Class1
{
public Class1()
{
Console.WriteLine("Creating Class1 in Namespace1");
}
}
} // End of namespace
namespace Namespace2
{
class Class1
{
public Class1()
{
Console.WriteLine("Creating Clas1 in Namespace2");
}

public static void Main()
{
Class1 class1_2 = new Class1();
Namespace1.Class1 class1_1 = new Namespace1.Class1();
Console.ReadLine();
}
}

}

Nov 15 '05 #4
As a preface, I don't think it's very good organization to have
mutliple classes in the same text file. I would try separating them
out by directory, something like this:
ProjectDirectory
Source
Namespace1
Class1.cs
Namespace2
Class1.cs
Bin
Doc
you get the idea...

But if you do wish to put two classes into the same file, here's what
I did:

The way I did it originally was just to type the 2nd namespace into
the default Class1.cs file of the project, and then compile it. Is
this what you are doing? How does the IDE protest? When you compile?

If you have a file called Class1.cs with two classes in it (like my
previous post) I can add it to a new project (one that does not have a
Class1.cs) as follows:
In solution explorer:
Right click on the project name:
Add existing item
Pick Class1.cs from the dialog
It adds it just fine.

Also, I can add a new class into an existing file with the wizard.
Goto class view. You'll see the namespaces. You can add a third
class into the file:
Right click on the project
Add | class
Enter the following: Class: Class1, Namespace: Namespace3
Hit ok
It prompts me: Class1.cs already exists. Do you want to merge to it?
I hit yes.

mike
"Jan Michalski" <ja***********@blueyonder.co.uk> wrote in message
news:zu******************@news-binary.blueyonder.co.uk...
Dear Michael,

The file structure I have is the same as yours.

Can you briefly outline how you incorporate this file into your
project.When I create my project it automatically creates a namespace with the same name as the project name. And I cannot see how to incorporate further namespaces. I have tried to add two classes with the same name but different namespaces. And then the IDE protests. Clearly this approach must be incorrect. How do you do it?

Regards,
Jan

Nov 15 '05 #5

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

Similar topics

3
2261
by: Charlie Calvert | last post by:
I'm new to C# and am used to Java, where there is a correspondence between package names and directories. I'm having trouble creating the same functionality in Visual Studio. In particular, I'm having trouble compiling such projects. As an example, suppose I have a project called ConsoleApplication1. It is stored in a directory called...
11
1739
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 understand that you declare your intention to use a namespace within a page through the "Inherits" attribute. I know that using "Inherits" isn't...
4
1436
by: Matt Jensen | last post by:
Howdy Relatively new to .NET, I'm trying to create custom a namespace for use in creating some utility classes, which I seem to have done OK, however, I'm having a problem trying to use the class with the error the namespace can't be found. I've really got no idea what I'm doing, I'm coding in C# and essentially using notepad, and trying...
4
396
by: mabster | last post by:
Hi folks, I'm just starting to come to grips with web services in general, and I'm in the process of making some test projects based on example code from MSDN etc. When I create a new ASP.NET web service, VS.NET makes a new .cs file for me that includes the web service class itself, inside a new namespace. In an example today (to...
1
1265
by: Giulio Petrucci | last post by:
Hi everybody, I'm getting confused about "which-name-give-to-what" developing my applications using Visual Studio. If I have to develop a "Utilities" library containing some classes for logging and other classes used for cryptography shall I build a new Solution named "Utilities"? And how many projects shall I set in it? Let's suppose I...
6
1711
by: =?Utf-8?B?TUNN?= | last post by:
What is the difference between importing a namespace at the: 1. Project level 2. web.config level 3. Page level What are the requirements/benefits of each? If I import a namespace such as System.Collections at the Project level and the user calls a page that does not use that namespace, is that wasting
0
7276
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...
0
7408
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. ...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
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...
1
5110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4773
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...
0
3267
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...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.