views:

22

answers:

2

Hi, 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

A: 

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();
        }
    }
}
Darin Dimitrov
Thanks Darin for answer. I have checked those classes and they are public, but I am not able to add namespace itself so not sure whether classes will be accessible or not.
Shekhar
Thanks for example. I'll remember to provide example from next time. So as shown in example, I am not able to access 'Project2' namespace itself in project1.
Shekhar
@shekhar, what do you mean you are not able to add namespace? Are you getting an error?
Darin Dimitrov
@Darin, I am not getting any error. What I mean is, intellisense is not listing 'Project2' when I type 'using'
Shekhar
A: 

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

Philip Smith