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


C# StringCollection.GetEnumerator方法代码示例

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


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

示例1: GetEnumerator_ModifiedCollectionTest

 public static void GetEnumerator_ModifiedCollectionTest(StringCollection collection, string[] data)
 {
     StringEnumerator enumerator = collection.GetEnumerator();
     Assert.NotNull(enumerator);
     if (data.Length > 0)
     {
         Assert.True(enumerator.MoveNext());
         string current = enumerator.Current;
         Assert.Equal(data[0], current);
         collection.RemoveAt(0);
         if (data.Length > 1 && data[0] != data[1])
         {
             Assert.NotEqual(current, collection[0]);
         }
         Assert.Equal(current, enumerator.Current);
         Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
         Assert.Throws<InvalidOperationException>(() => enumerator.Reset());
     }
     else
     {
         collection.Add("newValue");
         Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:24,代码来源:StringCollectionTests.cs

示例2: runTest

 public virtual 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";
     StringCollection sc; 
     StringEnumerator en; 
     string curr;        
     bool res;           
     string [] values = 
     {
         "a",
         "aa",
         "",
         " ",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     try
     {
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. Reset() on empty collection");
         Console.WriteLine("     - Reset()");
         iCountTestcases++;
         en = sc.GetEnumerator();
         try 
         {
             en.Reset();
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, unexpected exception: " + e.ToString());
         }
         Console.WriteLine("     - Current");
         iCountTestcases++;
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0001b, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001c, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("     - Add item to the collection");
         iCountTestcases++;
         int cnt = sc.Count;
         sc.Add(values[0]);
         if ( sc.Count != 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001d, failed to add item");
         }
         Console.WriteLine("     - Reset() on modified collection");
         try 
         {
             en.Reset();
             iCountErrors++;
             Console.WriteLine("Err_0001e, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001f, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. Reset() on filled collection");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         sc.AddRange(values);
         en = sc.GetEnumerator();
         Console.WriteLine("     - Reset() after Reset()");
         iCountTestcases++;
         try 
         {
             en.Reset();
             en.Reset();
         }
         catch (Exception e) 
         {
             iCountErrors++;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co8770reset.cs

示例3: GetEnumeratorTest

        public static void GetEnumeratorTest(StringCollection collection, string[] data)
        {
            bool repeat = true;
            StringEnumerator enumerator = collection.GetEnumerator();
            Assert.NotNull(enumerator);
            while (repeat)
            {
                Assert.Throws<InvalidOperationException>(() => enumerator.Current);
                foreach (string element in data)
                {
                    Assert.True(enumerator.MoveNext());
                    Assert.Equal(element, enumerator.Current);
                    Assert.Equal(element, enumerator.Current);
                }
                Assert.False(enumerator.MoveNext());
                Assert.Throws<InvalidOperationException>(() => enumerator.Current);
                Assert.False(enumerator.MoveNext());

                enumerator.Reset();
                enumerator.Reset();
                repeat = false;
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:23,代码来源:StringCollectionTests.cs

示例4: runTest

 public virtual 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";
     StringCollection sc; 
     StringEnumerator en; 
     string curr;        
     string [] values = 
     {
         "a",
         "aa",
         "",
         " ",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     try
     {
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. Enumerator for empty collection");
         Console.WriteLine("     - get type");
         iCountTestcases++;
         en = sc.GetEnumerator();
         string type = en.GetType().ToString();
         if ( type.IndexOf("StringEnumerator", 0) == 0 ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001a, type is not StringEnumerator");
         }
         Console.WriteLine("     - MoveNext");
         iCountTestcases++;
         bool res = en.MoveNext();
         if ( res ) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001b, MoveNext returned true");
         }
         Console.WriteLine("     - Current");
         iCountTestcases++;
         try 
         {
             curr = en.Current;
             iCountErrors++;
             Console.WriteLine("Err_0001c, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001d, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("     - Add item to the collection");
         iCountTestcases++;
         int cnt = sc.Count;
         sc.Add(values[0]);
         if ( sc.Count != 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001e, failed to add item");
         }
         Console.WriteLine("     - MoveNext on modified collection");
         try 
         {
             res = en.MoveNext();
             iCountErrors++;
             Console.WriteLine("Err_0001f, no exception");
         }
         catch (InvalidOperationException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001g, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("2. Enumerator for filled collection");
         strLoc = "Loc_002oo"; 
         iCountTestcases++;
         sc.AddRange(values);
         Console.WriteLine("     - get type");
         iCountTestcases++;
         en = sc.GetEnumerator();
         type = en.GetType().ToString();
         if ( type.IndexOf("StringEnumerator", 0) == 0 ) 
         {
             iCountErrors++;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8769movenext.cs


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