示例#1
0
        /// <summary>
        /// Overriden to check if two bit arrays are equal
        /// </summary>
        /// <param name="obj">Later is cast to a "BitArray64"</param>
        /// <returns>True or false of two BitArray64 comparison</returns>
        public override bool Equals(object obj)
        {
            BitArray64 bitArr = obj as BitArray64;

            if (obj == null) // We can add another check: this == null, otherwise it throws an exception
            {
                return(false);
            }

            return(Object.Equals(this.Number, bitArr.Number));
        }
        static void Main()
        {
            // Make instance of class "BitArray64"
            BitArray64 array1 = new BitArray64(5);
            BitArray64 array2 = null;
            BitArray64 array3 = new BitArray64(5);

            // Check if "IEnumerable<int>" is properly implemented
            Console.WriteLine("Bits in array, print with the help of IEnumerable<int>");
            foreach (var number in array1)
            {
                Console.Write(number);
            }

            Console.WriteLine();
            Console.WriteLine(new string('=', Console.WindowWidth - 1));

            // Check if method "Equals()" is properly implemented
            Console.WriteLine("Is array1 equals array2: {0}", array1.Equals(array2));
            Console.WriteLine("Is array1 equals array3: {0}", array1.Equals(array3));

            Console.WriteLine(new string('=', Console.WindowWidth - 1));

            // Check if operator "==" is properly implemented
            Console.WriteLine("Is array1 equals array2: {0}", array1 == array2);
            Console.WriteLine("Is array1 equals array3: {0}", array1 == array3);

            Console.WriteLine(new string('=', Console.WindowWidth - 1));

            // Check if operator "!=" is properly implemented
            Console.WriteLine("Is array1 don't equals array2: {0}", array1 != array2);
            Console.WriteLine("Is array1 don't equals array2: {0}", array1 != array3);

            Console.WriteLine(new string('=', Console.WindowWidth - 1));

            // Check if indexator is properly implemented
            Console.WriteLine("Bit at position 2: {0}", array1[2]);

            Console.WriteLine(new string('=', Console.WindowWidth - 1));

            // Check if "ToString" is properly implemented
            Console.WriteLine(array1);
        }
示例#3
0
 /// <summary>
 /// Overriden to compare the values of bit arrays
 /// </summary>
 /// <param name="bitArray1">First bit array</param>
 /// <param name="bitArray2">Second bit array</param>
 /// <returns>Comparison of two bit arrays</returns>
 public static bool operator !=(BitArray64 bitArray1, BitArray64 bitArray2)
 {
     return(!(BitArray64.Equals(bitArray1, bitArray2)));
 }