static void Main()
        {
            StringCollection scol = new StringCollection();

            scol.Add("Tiger");
            scol.Add("Lion");
            scol.Add("Cheetah");
            scol.Add("Panther");
            scol.Add("Lynx");


            Console.WriteLine("Printing the Elements");
            foreach (var item in scol)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("****************************************");
            Console.WriteLine("Printing Elements using the GetEnumerator Method");

            StringEnumerator se = scol.GetEnumerator();


            while (se.MoveNext())
            {
                Console.WriteLine(se.Current);
            }
            se.Reset();
        }
示例#2
0
        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());
            }
        }
        static void Main()
        {
            StringCollection mySEnum = new StringCollection();

            mySEnum.Add("This");
            mySEnum.Add("is");
            mySEnum.Add("String");
            mySEnum.Add("Enumerator");
            mySEnum.Add("Demo");


            // Enumerates the elements in the StringCollection.
            StringEnumerator myEnumerator = mySEnum.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                Console.WriteLine("{0}", myEnumerator.Current);
            }
            Console.WriteLine();

            //// Resets the enumerator and displays the first element again.
            myEnumerator.Reset();
            if (myEnumerator.MoveNext())
            {
                Console.WriteLine("The first element is {0}.", myEnumerator.Current);
            }
        }
示例#4
0
        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;
            }
        }
        static void Main()
        {
            StringCollection sc = new StringCollection();

            sc.Add("red");
            sc.Add("blue");
            sc.Add("green");
            sc.Add("yellow");
            sc.Add("brown");

            StringEnumerator en = sc.GetEnumerator();

            Console.WriteLine("---move next method---");

            while (en.MoveNext())
            {
                Console.WriteLine(en.Current);
            }
            en.Reset();
        }
        static void Main(string[] args)
        {
            StringCollection str = new StringCollection();

            str.Add("1");
            str.Add("2");
            str.Add("3");
            str.Add("4");
            str.Add("5");
            foreach (var i in str)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("enumerating elements .....");
            StringEnumerator stre = str.GetEnumerator();

            while (stre.MoveNext())
            {
                Console.WriteLine("{0}", stre.Current);
            }
            Console.WriteLine("resetting the enumerator...");
            stre.Reset();
            if (stre.MoveNext())
            {
                Console.WriteLine("The first element is {0}.", stre.Current);
            }
            Console.WriteLine("finding the type of elements in the collection.....");
            var k = stre.GetType();

            Console.WriteLine(k);
            Console.WriteLine("finding whether the specified element is equal to all elements in collection...");
            var l = stre.Equals("1");

            Console.WriteLine(l);
            Console.WriteLine("gets the hashcode of the elements...");
            var m = stre.GetHashCode();

            Console.WriteLine(m);
            Console.Read();
        }
        static void Main(string[] args)
        {
            //Creates and initializes a StringCollection.
            StringCollection myCol = new StringCollection();

            String[] myArr = new string[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet" };
            myCol.AddRange(myArr);
            //Enumerates the elements in the StringCollection.
            StringEnumerator myEnumerator = myCol.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                Console.WriteLine("{0}", myEnumerator.Current);
            }
            Console.WriteLine();
            //Resets the enumerator and displays the first element again.
            myEnumerator.Reset();
            if (myEnumerator.MoveNext())
            {
                Console.WriteLine("The first element is {0}.", myEnumerator.Current);
            }
        }
示例#8
0
 /// <summary>
 ///   Resets the enumeration.
 /// </summary>
 public void Reset()
 {
     m_senEnumerator.Reset();
 }
 public void Reset()
 {
     _stringEnumerator.Reset();
 }
 public void Reset()
 {
     _str.Reset();
 }
示例#11
0
 public void Reset() => stringEnumerator.Reset();