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


C# BitArray.GetEnumerator方法代码示例

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


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

示例1: GetEnumerator

 public static void GetEnumerator(bool[] values)
 {
     BitArray bitArray = new BitArray(values);
     Assert.NotSame(bitArray.GetEnumerator(), bitArray.GetEnumerator());
     IEnumerator enumerator = bitArray.GetEnumerator();
     for (int i = 0; i < 2; i++)
     {
         int counter = 0;
         while (enumerator.MoveNext())
         {
             Assert.Equal(bitArray[counter], enumerator.Current);
             counter++;
         }
         Assert.Equal(bitArray.Length, counter);
         enumerator.Reset();
     }
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:17,代码来源:BitArray_GetSetTests.cs

示例2: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     BitArray bitArr1;
     Boolean[] bolArr1;
     Int32 iNumOfElements;
     Int32 iCount;
     Random rnd1;
     Object oValue;
     IEnumerator ienm1;
     IEnumerator ienm2;
     ICloneable iclo1;
     try 
     {
         do
         {
             iNumOfElements = 10;
             rnd1 = new Random();
             strLoc = "Loc_742dsf!";
             iCountTestcases++;
             bolArr1 = new Boolean[iNumOfElements];
             for(int i=0; i<iNumOfElements; i++)
             {
                 if(rnd1.Next(10)>5)
                     bolArr1[i] = true;
                 else
                     bolArr1[i] = false;
             }
             bitArr1 = new BitArray(bolArr1);
             ienm1 = bitArr1.GetEnumerator();
             try
             {
                 oValue = ienm1.Current;
                 iCountErrors++;
                 Console.WriteLine("Err_535wsfd! No exception thrown");					
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_07842af! Unexpected exception thrown, " + ex);					
             }
             iCount=0;
         while(ienm1.MoveNext())
         {
             if((Boolean)ienm1.Current != bolArr1[iCount++])
             {
                 iCountErrors++;
                 Console.WriteLine("Err_753qn_" + iCount + "! Wrong value returned, " + ienm1.Current );
             }
         }
             try
             {
                 oValue = ienm1.Current;
                 Console.WriteLine(oValue);
                 iCountErrors++;
                 Console.WriteLine("Err_07214sff! No exception thrown");					
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_07842af! Unexpected exception thrown, " + ex);					
             }
             ienm1.Reset();
             iCount=0;
         while(ienm1.MoveNext())
         {
             if((Boolean)ienm1.Current != bitArr1[iCount++])
             {
                 iCountErrors++;
                 Console.WriteLine("Err_753qn_" + iCount + "! Wrong value returned, " + ienm1.Current );
             }
         }
             ienm1.Reset();
             iclo1 = (ICloneable)bitArr1.GetEnumerator();
             ienm2 = (IEnumerator)iclo1.Clone();
             iCount=0;
         while(ienm2.MoveNext())
         {
             if((Boolean)ienm2.Current != bitArr1[iCount++])
             {
                 iCountErrors++;
                 Console.WriteLine("Err_753qn_" + iCount + "! Wrong value returned, " + ienm2.Current );
             }
         }
             try
             {
                 oValue = ienm1.Current;
                 iCountErrors++;
                 Console.WriteLine("Err_0723sfg! No exception thrown");					
             }
             catch(InvalidOperationException)
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co3976getenumerator.cs

示例3: GetEnumerator_Invalid

        public static void GetEnumerator_Invalid()
        {
            BitArray bitArray = new BitArray(10, true);
            IEnumerator enumerator = bitArray.GetEnumerator();

            // Has not started enumerating
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            // Has finished enumerating
            while (enumerator.MoveNext()) ;
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            // Has resetted enumerating
            enumerator.Reset();
            Assert.Throws<InvalidOperationException>(() => enumerator.Current);

            // Has modified underlying collection
            enumerator.MoveNext();
            bitArray[0] = false;
            Assert.True((bool)enumerator.Current);
            Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
            Assert.Throws<InvalidOperationException>(() => enumerator.Reset());
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:23,代码来源:BitArray_GetSetTests.cs


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