命名空间中不存在! [英] namespace not found!

查看:333
本文介绍了命名空间中不存在!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个叫解。 增加一个类库名为 Foo.Common 增加了一个控制台应用程序调用的库code名为 ConsoleApp

I created a solution called Foo. Added a class library called Foo.Common Added a console app to call the library code from called ConsoleApp.

我所引用的 Foo.Common ConsoleApp ,然后键入:

I referenced the Foo.Common from ConsoleApp and typed :

using Foo.Common;
public class Program
{
    CommonClass c = new CommonClass();            

    static void Main(string[] args)
    {
    }
}

和得到这个回:

错误1类型或命名空间名称**美孚**'找不到(是否缺少using指令或程序集引用?)Z:\富\解决方法1 \ ConsoleApplication1 \程序的.cs 3 11 ConsoleApplication1

为什么会出现这个?

什么事了?

推荐答案

确认

  • ConsoleApp 的项目有一个参考的 Foo.Common 项目(做的没有的浏览对于Foo.Common.dll),

  • The ConsoleApp project has a reference to the Foo.Common project (do not browse for Foo.Common.dll),

该文件包含使用指令,其中 CommonClass 声明的命名空间,

the file contains a using directive for the namespace in which CommonClass is declared, and

CommonClass 被声明为公开

所以,你的文件应该是这样的:

So your files should look like this:

CommonClass.cs 的中的 Foo.Common 的项目:

namespace Foo.Common
{
    public class CommonClass
    {
        public CommonClass()
        {
        }
    }
}


的Program.cs 的中的 ConsoleApp 的项目:


Program.cs in ConsoleApp project:

using Foo.Common;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main()
        {
            CommonClass x = new CommonClass();
        }
    }
}

这篇关于命名空间中不存在!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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