Shekhar
Shekhar

Reputation: 11788

How to access namespace which is part of different project?

I have two C#.net projects project 1 and project 2 (names changed) in single solution. I am using Visual Studio 2005. I have added reference of project 2 in project 1 by right clicking and choosing 'Add Reference'. Both projects are of 'Application' project type not Class library type. I have some classes in project 2 which I want to access in project 1. After adding reference I tried to use import namespace of project 2 in project 1 but I guess its not available. Visual studio Intelisense is not showing me the desired namespace. Can anyone please suggest about how to access namespace and classes across multiple projects?

EDIT :- Is it because there are different assemblies for both the projects?

Thanks

Upvotes: 3

Views: 2296

Answers (2)

Philip Smith
Philip Smith

Reputation: 2801

Import is a Visual Basic.NET term. In C# you would use using.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039588

Make sure the classes you want to access are public. So suppose you have the following class in Project 2:

namespace Project2
{
    public class Foo { }
}

In Project 1 after you've referenced Project 2 you can use this class:

namespace Project1
{
    using Project2;

    public class Bar
    {
        public Bar()
        {
            Foo foo = new Foo();
        }
    }
}

Upvotes: 1

Related Questions