当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.GetEnumerator方法代码示例

本文整理汇总了C#中System.Collections.BitArray.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.GetEnumerator方法的具体用法?C# BitArray.GetEnumerator怎么用?C# BitArray.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.GetEnumerator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Equals

        /// <summary>
        /// Check if two arrays of bits are equals
        /// Returns true if every bit of this first array is equal to the corresponding bit of the second, false otherwise
        /// </summary>
        public static bool Equals(BitArray a, BitArray b)
        {
            if (a.Length != b.Length) return false;

            var enumA = a.GetEnumerator();
            var enumB = b.GetEnumerator();

            while (enumA.MoveNext() && enumB.MoveNext())
            {
                if ((bool)enumA.Current != (bool)enumB.Current) return false;
            }
            return true;
        }
开发者ID:hwpayg,项目名称:DotnetSpider,代码行数:17,代码来源:ObjectUtils.cs

示例2: InsertMessage

        public void InsertMessage(string message)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            var dataToEncode = Encoding.ASCII.GetBytes(message);

            byte[] dataWithMeta = new byte[dataToEncode.Length + MessageLength + MessageLengthPadding];


            //four bytes for message length; 2 bytes for padding
            var messageLengthInfo = BitConverter.GetBytes(message.Length);
            Array.Copy(messageLengthInfo, dataWithMeta, MessageLength);
            Array.Copy(dataToEncode, 0, dataWithMeta, MessageLength + MessageLengthPadding, dataToEncode.Length);

            BitArray bits = new BitArray(dataWithMeta);
            var e = bits.GetEnumerator();
            var bmpPixelEnumerator = new BitmapPixelEnumerator(_img);
            foreach (Pixel pixel in bmpPixelEnumerator)
            {

                byte oldBlue = pixel.Blue;
                byte oldGreen = pixel.Green;
                byte oldRed = pixel.Red;

                byte newBlue;
                if (InsertData(e, oldBlue, out newBlue)) return;
                _copy.SetPixel(pixel.X, pixel.Y, Color.FromArgb(newBlue, oldGreen, oldRed));


                byte newGreen;
                if (InsertData(e, oldGreen, out newGreen)) return;
                _copy.SetPixel(pixel.X, pixel.Y, Color.FromArgb(newBlue, newGreen, oldRed));


                byte newRed;
                if (InsertData(e, oldRed, out newRed)) return;
                _copy.SetPixel(pixel.X, pixel.Y, Color.FromArgb(newBlue, newGreen, newRed));
            }
            watch.Stop();
            Debug.WriteLine(watch.Elapsed);
        }
开发者ID:soltys,项目名称:ZUT_Stegano,代码行数:41,代码来源:BitmapManipulator.cs

示例3: BitArray_GetEnumeratorTest_Negative

            public static void BitArray_GetEnumeratorTest_Negative()
            {
                int size = 10;

                Boolean[] bolArr1 = new Boolean[size];

                for (int i = 0; i < size; i++)
                {
                    if (i > 5)
                        bolArr1[i] = true;
                    else
                        bolArr1[i] = false;
                }

                BitArray bitArr1 = new BitArray(bolArr1);
                IEnumerator ienm1 = bitArr1.GetEnumerator();

                // test that initially enumerator is positioned before the first element in the collection --> Current will be undefined
                Assert.Throws<InvalidOperationException>(delegate { Object obj = ienm1.Current; }); //"Err_40! wrong exception thrown."

                // get to the end of the collection
                while (ienm1.MoveNext()) ;

                // test that after MoveNext() returns false (i.e. we are at the end) enumerator is positioned after the last element in the collection --> Current will be undefined
                Assert.Throws<InvalidOperationException>(delegate { Object obj = ienm1.Current; }); //"Err_41! wrong exception thrown."


                //[] we will change the underlying BitArray and see the effect
                ienm1.Reset();
                ienm1.MoveNext();
                bitArr1[0] = false;

                // we do not throw exception when getting Current
                Object obj2 = ienm1.Current;

                // test that the enumerator is not valid after modifying collection
                Assert.Throws<InvalidOperationException>(delegate { ienm1.MoveNext(); }); //"Err_42! wrong exception thrown."
                Assert.Throws<InvalidOperationException>(delegate { ienm1.Reset(); }); //"Err_43! wrong exception thrown."
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:39,代码来源:BitArray_GetSetTests.cs

示例4: BitArray_GetEnumeratorTest

            public static void BitArray_GetEnumeratorTest()
            {
                int size = 10;

                Boolean[] bolArr1 = new Boolean[size];

                for (int i = 0; i < size; i++)
                {
                    if (i > 5)
                        bolArr1[i] = true;
                    else
                        bolArr1[i] = false;
                }

                BitArray bitArr1 = new BitArray(bolArr1);
                IEnumerator ienm1 = bitArr1.GetEnumerator();

                int iCount = 0;

                while (ienm1.MoveNext())
                {
                    Assert.Equal((Boolean)ienm1.Current, bolArr1[iCount++]); //"Err_26! wrong value returned"
                }

                ienm1.Reset();
                iCount = 0;
                while (ienm1.MoveNext())
                {
                    Assert.Equal((Boolean)ienm1.Current, bolArr1[iCount++]); //"Err_27! wrong value returned"
                }
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:31,代码来源:BitArray_GetSetTests.cs

示例5: BitArraysEqual

    /// <summary> Zjistí, jestli stejnì dlouhé BitArrays mají nastavené stejné bity. </summary>
    /// <param name="bits1"> 1. BitArray. </param>
    /// <param name="bits2"> 2. BitArray. </param>
    /// <returns> true, když mají nastavené stejné bity. </returns>
    public static bool BitArraysEqual ( BitArray bits1, BitArray bits2 )
    {
      if ( bits1.Count != bits2.Count )
        throw new Exception( string.Format( "OtherCore.BitArraysEqual: different BitArray sizes {0} != {1}", bits1.Count != bits2.Count ) );

      return EnumerablesAreSame( bits1.GetEnumerator(), bits2.GetEnumerator() );
//
//      int[] array1 = new int[ ( bits1.Count + 31 ) / 32 ];
//      bits1.CopyTo( array1, 0 );
//      int[] array2 = new int[ array1.Length ];
//      bits2.CopyTo( array2, 0 );
//
//      for ( int index = array1.Length ; --index >= 0 ; )
//        if ( array1[ index ] != array2[ index ] )
//          return false;
//
//      return true;
    }
开发者ID:PavelPZ,项目名称:NetNew,代码行数:22,代码来源:Other.cs


注:本文中的System.Collections.BitArray.GetEnumerator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。