我如何在C#中使用我的命名空间 [英] How I Use My Namespace In C#
问题描述
我在我的程序中添加由我创建的命名空间。
喜欢:
使用mynamespace;
但它给出错误
错误1类型或命名空间名称'ConsoleApplication2'可以找不到(你是否错过了使用指令或汇编参考?)
请解释使用指令和汇编参考
并解决问题详细示例
using directive是你的使用mynamespace;
一段代码。 程序集引用是对程序集的引用[ ^ ]。
在这种情况下,您可能缺少程序集引用。如果你的ConsoleApplication2
在另一个项目中(但在同一个解决方案中),那么:
- 转到解决方案资源管理器。
- 右键单击引用并选择添加引用。
- 在Visual Studio 2012/2013中,在VS中选择解决方案 2010,选择项目。
- 选择包含
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 yourusing mynamespace;
piece of code. An "assembly reference" is a reference to an assembly[^].
In this case, you are probably missing an assembly reference. If yourConsoleApplication2
is in another project (but in the same solution), then:
- Go to the Solution Explorer.
- Right-click on "References" and choose "Add Reference".
- In Visual Studio 2012/2013, choose "Solution", in VS 2010, choose "Projects".
- Select the project that contains your
ConsoleApplication2
namespace and click OK.
If theConsoleApplication2
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屋!