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


C# Collection.GetEnumerator方法代码示例

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


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

示例1: GetEnumerator_11

        public void GetEnumerator_11()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o1,en.Current);

            col.Remove(1);

            object o = en.Current;
            Assert.AreEqual (o1, o, "#01");
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:22,代码来源:CollectionTests.cs

示例2: GetEnumerator_13

        public void GetEnumerator_13()
        {
            Collection col = new Collection();

            string s1 = "e";
            string s2 = "g";
            string s3 = "a";
            string s4 = "f";
            string s5 = "q";

            col.Add(s1,null,null,null);
            col.Add(s2,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s1,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(s2,en.Current);
            Assert.IsFalse(en.MoveNext());
            Assert.AreEqual(null,en.Current);

            col.Add(s3,null,null,null);

            Assert.AreEqual(null,en.Current);

            col.Add(s4,null,null,null);
            col.Add(s5,null,null,null);

            Assert.IsFalse(en.MoveNext());
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:31,代码来源:CollectionTests.cs

示例3: GetEnumerator_1

        public void GetEnumerator_1()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;
            long o4 = 1000;
            Single o5 = 1.1F;
            Double o6 = 2.2;
            Decimal o7 = 1000;
            String o8 = "abc";
            Object o9 = null;
            bool o10 = true;
            Char o11 = 'c';
            DateTime o12 = DateTime.Parse("5/31/1993");

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);
            col.Add(o4,null,null,null);
            col.Add(o5,null,null,null);
            col.Add(o6,null,null,null);
            col.Add(o7,null,null,null);
            col.Add(o8,null,null,null);
            col.Add(o9,null,null,null);
            col.Add(o10,null,null,null);
            col.Add(o11,null,null,null);
            col.Add(o12,null,null,null);

            IEnumerator en = col.GetEnumerator();

            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o1,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o2,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o3,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o4,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o5,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o6,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o7,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o8,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o9,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o10,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o11,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o12,en.Current);
            Assert.IsFalse(en.MoveNext());
            Assert.AreEqual(null,en.Current);
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:59,代码来源:CollectionTests.cs

示例4: GetEnumerator_10

        public void GetEnumerator_10()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;
            long o4 = 1000;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            col.Add(o4,null,1,null);

            en.MoveNext();

            Assert.AreEqual(o4,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o1,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o2,en.Current);
            Assert.IsTrue(en.MoveNext());
            Assert.AreEqual(o3,en.Current);
            Assert.IsFalse(en.MoveNext());
            Assert.AreEqual(null,en.Current);

            col.Add(o4,null,null,null);

            Assert.AreEqual(null,en.Current);
            Assert.IsFalse(en.MoveNext());
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:34,代码来源:CollectionTests.cs

示例5: GetEnumerator

        public void GetEnumerator()
        {
            Collection c;
            IEnumerator e;
            object[] o = new object[4] {typeof(int),
                                           typeof(double), typeof(string), typeof(object)};
            int i = 0;

            c = new Collection ();

            c.Add (typeof (int), null, null, null);
            c.Add (typeof (double), null, null, null);
            c.Add (typeof (string), null, null, null);
            c.Add (typeof (object), null, null, null);

            e = c.GetEnumerator ();

            Assert.IsNotNull (e, "#GE01");

            while (e.MoveNext ())
            {
                Assert.AreEqual (o[i], e.Current, "#GE02." + i.ToString ());
                i++;
            }

            e.Reset ();
            e.MoveNext ();

            Assert.AreEqual (o[0], e.Current, "#GE03");
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:30,代码来源:CollectionTests.cs

示例6: Exception


//.........这里部分代码省略.........

            try
            {
                // Even though Before is object, it's really a string
                c.Add ("Dodgeball", "Dodge", typeof (int), null);
                Assert.Fail ("#E16");
            }
            catch (InvalidCastException)
            {
            }

            try
            {
                // Even though After is object, it's really a string
                c.Add ("Wallyball", "Wally", null, typeof (int));
                Assert.Fail ("#E18");
            }
            catch (InvalidCastException)
            {
            }

            try
            {
                // have to pass a legitimate value to remove
                c.Remove (null);
                Assert.Fail ("#E20");
            }
            catch (ArgumentNullException)
            {
            }

            try
            {
                // no Key "Golf" exists
                c.Remove ("Golf");
                Assert.Fail ("#E22");
            }
            catch (ArgumentException)
            {
            }

            try
            {
                // no Index 10 exists
                c.Remove (10);
                Assert.Fail ("#E24");
            }
            catch (IndexOutOfRangeException)
            {
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();

                // Must MoveNext before Current
                object item = e.Current;
                Assert.IsNull (item, "#E25");
            }
            catch (IndexOutOfRangeException)
            {
                Assert.Fail ("#E27");
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();
                e.MoveNext ();

                c.Add ("Paintball", "Paint", null, null);

                // Can't MoveNext if Collection has been modified
                e.MoveNext ();

                // FIXME
                // On-line help says this should throw an error. MS doesn't.
            }
            catch (Exception)
            {
                Assert.Fail ("#E28");
            }

            try
            {
                IEnumerator e = c.GetEnumerator ();
                e.MoveNext ();

                c.Add ("Racketball", "Racket", null, null);

                // Can't Reset if Collection has been modified
                e.Reset ();

                // FIXME
                // On-line help says this should throw an error. MS doesn't.
            }
            catch (InvalidOperationException)
            {
                Assert.Fail ("#E30");
            }
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:101,代码来源:CollectionTests.cs

示例7: GetEnumerator_8

        public void GetEnumerator_8()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            en.MoveNext();

            col.Remove(3);
            col.Remove(2);

            Assert.AreEqual(o1,en.Current);
            Assert.IsFalse(en.MoveNext());
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:22,代码来源:CollectionTests.cs

示例8: GetEnumerator_7

        public void GetEnumerator_7()
        {
            Collection col = new Collection();

            Byte o1 = 1;
            short o2 = 1;
            int o3 = 1;

            col.Add(o1,null,null,null);
            col.Add(o2,null,null,null);
            col.Add(o3,null,null,null);

            IEnumerator en = col.GetEnumerator();

            en.MoveNext();

            col.Remove(1);

            object o = en.Current;
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:20,代码来源:CollectionTests.cs

示例9: GetEnumerator_2

        public void GetEnumerator_2()
        {
            // Collection index must be in the range 1 to the size of the collection.
            Collection col = new Collection();

            col.Add("a",null,null,null);

            IEnumerator en = col.GetEnumerator();

            object o = en.Current;
        }
开发者ID:h-endo12345,项目名称:mono-basic,代码行数:11,代码来源:CollectionTests.cs


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