我如何在C#中使用我的命名空间 [英] How I Use My Namespace In C#

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

问题描述

我在我的程序中添加由我创建的命名空间。



喜欢:



使用mynamespace;



但它给出错误



错误1类型或命名空间名称'ConsoleApplication2'可以找不到(你是否错过了使用指令或汇编参考?)



请解释使用指令和汇编参考



并解决问题详细示例

解决方案

using directive是你的使用mynamespace; 一段代码。 程序集引用是对程序集的引用[ ^ ]。



在这种情况下,您可能缺少程序集引用。如果你的 ConsoleApplication2 在另一个项目中(但在同一个解决方案中),那么:



  1. 转到解决方案资源管理器。
  2. 右键单击引用并选择添加引用。
  3. 在Visual Studio 2012/2013中,在VS中选择解决方案 2010,选择项目。
  4. 选择包含 ConsoleApplication2 命名空间的项目,然后单击确定。



如果 ConsoleApplication2 项目不在同一解决方案中,则选择浏览而不是解决方案,然后从文件系统中选择所需的程序集。 / blockquote>

您没有提供有关您的问题的足够信息。



我建议您阅读以下内容:

1.12命名空间和程序集 [ ^ ]

使用命名空间(C#编程指南) [ ^ ]

如何:使用全局命名空间别名(C#编程指南) [ ^ ]

如何:使用My Namespace(C#编程指南) [ ^ ]


i add namespace which created by me in my program .

like that:

using mynamespace;

but it giving error

"Error 1 The type or namespace name 'ConsoleApplication2' could not be found (are you missing a using directive or an assembly reference?) "

please explain " using directive " and "assembly reference"

and solve problem with detail example

解决方案

The "using directive" is your using mynamespace; piece of code. An "assembly reference" is a reference to an assembly[^].

In this case, you are probably missing an assembly reference. If your ConsoleApplication2 is in another project (but in the same solution), then:


  1. Go to the Solution Explorer.
  2. Right-click on "References" and choose "Add Reference".
  3. In Visual Studio 2012/2013, choose "Solution", in VS 2010, choose "Projects".
  4. Select the project that contains your ConsoleApplication2 namespace and click OK.


If the ConsoleApplication2 project is not in the same solution, then chooose "Browse" instead of "Solution" and choose the desired assembly from your file system.


You did not provide enough information about your issue.

I'd suggest to read these:
1.12 Namespaces and assemblies[^]
Using Namespaces (C# Programming Guide)[^]
How to: Use the Global Namespace Alias (C# Programming Guide)[^]
How to: Use the My Namespace (C# Programming Guide)[^]


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

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