【发布时间】:2020-11-23 06:52:31
【问题描述】:
我在 Visual Studio 2019 中编写了以下代码,但它给了我一个错误,说 BitVector32 是一个命名空间,但在此处用作类型,而 CreateMask() 方法不是存在于 BitVector32 命名空间中
using System;
using System.Collections.Specialized;
namespace BitVector32
{
class Program
{
static void Main(string[] args)
{
basicVector();
}
public static void basicVector()
{
BitVector32 b = new BitVector32(0);
int myBit1 = BitVector32.CreateMask();
int myBit2 = BitVector32.CreateMask(myBit1);
int myBit3 = BitVector32.CreateMask(myBit2);
int myBit4 = BitVector32.CreateMask(myBit3);
int myBit5 = BitVector32.CreateMask(myBit4);
}
}
}
我在https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.bitvector32?view=netcore-3.1 引用了 Microsoft 文档并做了同样的事情,但它给出了上述错误
【问题讨论】:
-
您会在此处看到程序的第 4 行,在那里您将名称
BitVector32重用为命名空间。这就是编译器在System.Collections.Specialized中收集同名之前的发现 - 尝试在命名项目/命名空间时更具创意。
标签: c# collections namespaces visual-studio-2019 bitvector