Search code examples
c#collectionsnamespacesvisual-studio-2019bitvector

Namespace error while defining a BitVector32 collection in C#


I have written the following code in visual studio 2019, but it gives me an error saying that BitVector32 is a namespace but is used as a type here and CreateMask() method is not existing in the BitVector32 namespace

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);

        }

    }
}

i referred the Microsoft doc at https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.bitvector32?view=netcore-3.1 and did the same but it gives the above mentioned errors


Solution

  • This is due to your namespace at the top being BitVector32. Change the namespace to another name other than BitVector32:

    using System;
    using System.Collections.Specialized;
    
    namespace SomethingOtherThanBitVector32
    {
        class Program
        {
            static void Main(string[] args)
            {
                basicVeector();
            }
    
            public static void basicVeector()
            {
    
                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);
    
            }
    
        }
    }