C# Net Class 引用的类库 : why must I fully qualify a public class?

标签 c# class namespaces naming fully-qualified-naming

有一个烦人的问题,尽管我已经构建了一个类并在如下所示的客户端程序中引用了它 - 通过使用,编译器想要我的方法的完全限定名称。

// this doesn't compile because it does not recognize the Decrypt method
using PGPEncryptDecrypt.Helpers.PGP;

namespace TestComInterOpPGP
{
class Program
{
    static void Main(string[] args)
    {
         PGPEncryptDecrypt.Decrypt(@"C:\Users\blah.pgp",
            @"C:\Users\secring.gpg",
            "pwd",
            @"C:\Users\out.txt");

    }
}
}

必须完全合格
// this does compile
using PGPEncryptDecrypt.Helpers.PGP;

namespace TestComInterOpPGP
{
class Program
{
    static void Main(string[] args)
    {
         PGPEncryptDecrypt.Helpers.PGP.PGPEncryptDecrypt.Decrypt(@"C:\Users\blah.pgp",
            @"C:\Users\secring.gpg",
            "pwd",
            @"C:\Users\out.txt");

    }
}
}

最佳答案

啊 - 在输入这个时我意识到问题是 PGPEncryptDecrypt 类与命名空间的第一部分具有相同的名称。所以我只是改变了其中一个,不需要完全合格。也许这会帮助某人!

关于C# Net Class 引用的类库 : why must I fully qualify a public class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21197054/

相关文章:

c++ - 匿名命名空间类定义

c# - 如何创建具有异步功能的类(类似于 SqlCommand 或 WebRequest)?

c# - 字典包含值并一步获取 key 或有效的方式来完成这项任务?

python - (Python) 当我在类定义之后调用方法对象时,为什么它不执行?

php - 在 PHP 中是否有动态扩展类的选项?

xml - 元素中 XML 命名空间的错误输出

c# - EF Code First 如何为派生类创建单独的表?

c# - 通过 XAML 绑定(bind)将静态只读值作为 CommandParameter 传递?

C++:隐藏基本静态成员

xml - XML 中命名空间的需要