如何访问属于不同项目的名称空间? [英] How to access namespace which is part of different project?

查看:104
本文介绍了如何访问属于不同项目的名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个解决方案中有两个C#.net项目project 1和project 2(名称更改).我正在使用Visual Studio2005.通过右键单击并选择添加引用",在项目1中添加了项目2的引用.这两个项目都是应用程序"项目类型,而不是类库类型.我在项目2中有一些要在项目1中访问的类.添加引用后,我尝试在项目1中使用项目2的导入名称空间,但我想它不可用. Visual Studio Intelisense没有向我显示所需的名称空间. 任何人都可以提出有关如何跨多个项目访问名称空间和类的建议吗?

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?

谢谢

推荐答案

确保要访问的类是公共的.因此,假设您在Project 2中有以下课程:

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 { }
}

在引用了Project 2之后,在Project 1中可以使用此类:

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

这篇关于如何访问属于不同项目的名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆