【发布时间】:2014-04-24 12:44:01
【问题描述】:
我创建了一个 dll,其中包含一个带有公共方法的公共类。
我在新项目中添加了该 dll 作为参考,我正在尝试从 dll 的类中创建一个新对象
using myDll;
namespace foo
{
class bar
{
static void Main(string[] args)
{
myDll.myClass test = new myDll.myClass();
test.myVoidMethod();
[...]
但是当我尝试使用 test 视觉工作室时说
The type or namespace name 'test' could not be found (are you missing a using directive or an assembly reference?)
这是范围问题吗?
mydll 代码(摘录):
using System;
namespace myDll
{
public class myClass
{
public static void myVoidMethod()
{
Console.Write("Hello");
}
}
}
【问题讨论】:
-
您对这个问题的答案可以在这篇文章中找到:stackoverflow.com/questions/6715612/…
-
确保没有
test类或命名空间——这很可能会导致混淆(但可能不是错误的情况)。旁注:通常以大写命名的 C# 类/方法... -
@Thomas:我添加了 dll 代码
-
@AlexeiLevenkov:没有冲突的命名空间/类/什么...(上面的代码只是我的情况的一个例子)
-
那代码不可能是正确的 - 你在一个实例变量上调用一个静态方法。
标签: c# visual-studio-2012 namespaces scope