sai sindhu
sai sindhu

Reputation: 1155

C# Namespace issue

I am new to C# and I wish to know how to use my own namespace in c#.

Suppose I have a namespace MyNamespace1.

And I have another namespace MyNamespace2. I want to use MyNamespace1. But when I use

using MyNamespace1;

it is not recognizable.I want to know how to do this.

Upvotes: 0

Views: 224

Answers (3)

Niranjan Singh
Niranjan Singh

Reputation: 18290

MSDN is your friend in learning about this.

The namespace keyword is used to declare a scope. 

namespaces used to organize it's many classes

namespace N1     // N1
{
    class C1      // N1.C1
    {
        class C2   // N1.C1.C2
        {
        }
    }
    namespace N2  // N1.N2
    {
        class C2   // N1.N2.C2
        {
        }
    }
}

Using Namespaces (C# Programming Guide)

Check your accessibility level of your namespace. If it is in same project then you can access it directly.

using YourProjectName.NamespaceThatYouCreated;

If it is another project like dll etc then add reference to that library or project. access namespace as:

using AnotherProject.CreatedNameSpacename;

Upvotes: 3

ABH
ABH

Reputation: 3439

If both of your name spaces are in different project then you must add the reference of the other project to access it's namespace. In your case add the project reference of MyNamespace1 to the project the project of MyNamespace2.

Upvotes: 0

Christophe De Troyer
Christophe De Troyer

Reputation: 2922

http://msdn.microsoft.com/en-us/library/z2kcy19k%28v=vs.80%29.aspx

and this one in particular: http://www.csharp-station.com/Tutorials/Lesson06.aspx

Also, what I've discovered, if you're using asp.net you might need to change the property "Build action" of the class you wish to use in your page to "Compile".

Upvotes: 0

Related Questions