gpt4 book ai didi

c# - 冲突的命名空间解析

转载 作者:行者123 更新时间:2023-12-04 16:53:24 24 4
gpt4 key购买 nike

我正在使用一个名为 BCrypt.net 的库,作者将Namespace 与Class 同名,所以Class 全路径为:BCrypt.Net.BCrypt,其中BCrypt.Net 为Namespace,BCrypt 为Class 名称。

我正在尝试在我的代码中使用,就像我能找到的所有示例一样,例如:

BCrypt.HashPassword("234");

但是 Visual Studio 提示说:

Error 3 The type or namespace name 'HashPassword' does not exist in the namespace 'BCrypt' (are you missing an assembly reference?)



我的项目中有程序集(因为我是从 NuGet 得到的):

Assembly Reference

如果我添加一个 using BCrypt.Net;using BCrypt; ,在我的命名空间之前,错误说明相同。
我将它添加到我的命名空间中,发生了一些有趣的事情。我工作,代码编译并执行。但是 Visual Studio 显示错误!我无法理解它是如何编译出错的。
namespace Test.Data
{
using BCrypt.Net; // The 'Net' is marked with a Red Error line in VS2013
....
string s = BCrypt.HashPassword("234");

Error 3 The type name 'Net' does not exist in the type >'BCrypt.Net.BCrypt'


using BCrypt = BCrypt.Net.BCrypt; 的错误(但编译和执行正常)相同

发生什么了?

编辑:

我知道我可以用它作为 BCrypt.Net.BCrypt.HashPassword("234"); ,但我想避免它。

最佳答案

添加

using BCrypt = BCrypt.Net.BCrypt;

到您的用途:
namespace YourNamespace
{
using BCrypt = BCrypt.Net.BCrypt;

class Program
{
static void Main(string[] args)
{
BCrypt.HashPassword("234");
}
}

打样画面:

VS 2015 likes this

关于c# - 冲突的命名空间解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31844709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com