How to access namespace which is part of different project?

心不动则不痛 提交于 2019-12-01 23:25:03

问题


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


回答1:


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();
        }
    }
}



回答2:


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



来源:https://stackoverflow.com/questions/3350939/how-to-access-namespace-which-is-part-of-different-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!