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


C# Queue.GetEnumerator方法代码示例

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


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether GetEnumerator() is successful when the queue is not empty.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            for (int i = 0; i < TestQueue.Count; i++)
            {
                if (TestQueue.ToArray()[i] != TestEnumerator.Current)
                {
                    TestLibrary.TestFramework.LogError("P01.1", "GetEnumerator() failed when the queue is not empty!");
                    retVal = false;
                }
                TestEnumerator.MoveNext();
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:34,代码来源:queuegetenumerator.cs

示例2: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: The enumerator should be positioned at the first element in the collection after MoveNext().");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            string TestString = TestEnumerator.Current;
            if (TestString != "one")
            {
                TestLibrary.TestFramework.LogError("P01.1", "The enumerator is not positioned at the first element in the collection after MoveNext()!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:30,代码来源:enumeratormovenext.cs

示例3: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Resource of the Enumerator should be released after Dispose().");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            TestEnumerator.Dispose();
            string TestString = TestEnumerator.Current;
            TestLibrary.TestFramework.LogError("P01.1", "Resource of the Enumerator have not been released after Dispose()!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:32,代码来源:enumeratordispose.cs

示例4: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest2: Test whether GetEnumerator() is successful when the queue is empty.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            try
            {
                string CurrentElement = TestEnumerator.Current;
                TestLibrary.TestFramework.LogError("P02.1", "GetEnumerator() failed when the queue is empty!");
                retVal = false;
            }
            catch (InvalidOperationException)
            {

            }
            bool b = TestEnumerator.MoveNext();
            if (b != false)
            {
                TestLibrary.TestFramework.LogError("P02.2", "GetEnumerator() failed when the queue is empty!");
                retVal = false;
            }
            try
            {
                string CurrentElement = TestEnumerator.Current;
                TestLibrary.TestFramework.LogError("P02.3", "GetEnumerator() failed when the queue is empty!");
                retVal = false;
            }
            catch (InvalidOperationException)
            {

            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P02.4", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:46,代码来源:queuegetenumerator.cs

示例5: Clear_Normal

        public void Clear_Normal()
        {
            var q = new Queue<string>();
            Assert.Equal(0, q.Count);

            for (int repeat = 0; repeat < 2; repeat++) // repeat to ensure we can grow after emptying
            {
                // Add some elements
                for (int i = 0; i < 5; i++)
                {
                    q.Enqueue(i.ToString());
                }
                Assert.Equal(5, q.Count);
                Assert.True(q.GetEnumerator().MoveNext());

                // Clear them and make sure they're gone
                q.Clear();
                Assert.Equal(0, q.Count);
                Assert.False(q.GetEnumerator().MoveNext());
            }
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:21,代码来源:QueueTests.cs

示例6: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest1: Current() should be successful.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            if (TestEnumerator.Current != "one")
            {
                TestLibrary.TestFramework.LogError("P01.1", "Current() failed!");
                retVal = false;
            }
            TestEnumerator.MoveNext();
            if (TestEnumerator.Current != "two")
            {
                TestLibrary.TestFramework.LogError("P01.2", "Current() failed!");
                retVal = false;
            }
            TestEnumerator.MoveNext();
            if (TestEnumerator.Current != "three")
            {
                TestLibrary.TestFramework.LogError("P01.3", "Current() failed!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P01.4", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:40,代码来源:enumeratorcurrent.cs

示例7: Main

        static void Main(string[] args)
        {
            Queue<DateTime> aq = new Queue<DateTime>();
            aq.Enqueue(new DateTime(2008, 1, 19));   // item 1
            aq.Enqueue(new DateTime(2008, 4, 5));   // item 2
            aq.Enqueue(new DateTime(2008, 7, 2));   // item 3
            aq.Enqueue(new DateTime(2008, 12, 3));   // item 4

            Console.WriteLine("Count:    {0}", aq.Count);
            PrintValues(aq);

            // Peek item 1 but do not remove
            DateTime item = aq.Peek();
            Console.WriteLine("Peek: {0}", item.ToShortDateString());   // item is DateTime, not object
            PrintValues(aq);

            // Contains
            Boolean contains = aq.Contains(new DateTime(2008, 7, 2));
            Console.WriteLine("Contains: {0}", contains);

            // Remove items
            DateTime item1 = aq.Dequeue();
            DateTime item2 = aq.Dequeue();
            Console.WriteLine("Dequeue: {0}  {1}", item2.ToShortDateString(), item2.ToShortDateString());
            PrintValues(aq);
            Console.WriteLine("Count:    {0}", aq.Count);

            // Trim to size
            aq.TrimExcess();   // c.f. TrimToSize in non-generic Queue

            // iterate through Queue using a Queue.Enumerator
            Console.WriteLine("Listing using Queue.Enumerator");
            Queue<DateTime>.Enumerator qenum = aq.GetEnumerator();    // Queue<T>.Enumerator is a public inner struct declared in Queue<t>, see MyClass in this project for similar example
            while (qenum.MoveNext())
            {
                DateTime dt = qenum.Current;
                Console.WriteLine("{0}", dt.ToShortDateString());
            }
        }
开发者ID:BigBearGCU,项目名称:FNDEVModule2ExampleCode,代码行数:39,代码来源:Program.cs

示例8: PosTest3

    public bool PosTest3()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest3: The enumerator should be positioned after the last element in the collection after MoveNext() passed the end of collection.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            bool bSuc;
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            bSuc = TestEnumerator.MoveNext();
            if (bSuc)
            {
                TestLibrary.TestFramework.LogError("P03.1", "The enumerator is not positioned after the last element in the collection after MoveNext() passed the end of collection!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P03.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:35,代码来源:enumeratormovenext.cs

示例9: NegTest2

    public bool NegTest2()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("NegTest2: InvalidOperationException should be thrown when the enumerator is positioned after the last element of the collection.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            TestEnumerator.MoveNext();
            TestEnumerator.MoveNext();
            TestEnumerator.MoveNext();
            string TestString = TestEnumerator.Current;
            TestLibrary.TestFramework.LogError("N02.1", "InvalidOperationException is not thrown when the enumerator is positioned after the last element of the collection!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("N02.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:34,代码来源:enumeratorcurrent.cs

示例10: NegTest3

    public bool NegTest3()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("NegTest3: InvalidOperationException should be thrown when MoveNext after queue has been changed.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator = TestQueue.GetEnumerator();
            TestEnumerator.MoveNext();
            if (TestEnumerator.Current != "one")
            {
                TestLibrary.TestFramework.LogError("P02.1", "Current() failed!");
                retVal = false;
            }
            TestQueue.Dequeue();
            TestEnumerator.MoveNext();
            TestLibrary.TestFramework.LogError("P02.1", "InvalidOperationException not thrown when MoveNext after queue has been changed!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("N03.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:36,代码来源:enumeratorcurrent.cs

示例11: run


//.........这里部分代码省略.........
            LinkedList<int> l = new LinkedList<int>(arr);
            Test.IntLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<int> l2 = Test.IntLinkedListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            Test.MyEnum[] arr =
            {
                Test.MyEnum.enum3,
                Test.MyEnum.enum2,
                Test.MyEnum.enum1,
                Test.MyEnum.enum2
            };
            @out = new Ice.OutputStream(communicator);
            LinkedList<Test.MyEnum> l = new LinkedList<Test.MyEnum>(arr);
            Test.MyEnumLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<Test.MyEnum> l2 = Test.MyEnumLinkedListHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            @out = new Ice.OutputStream(communicator);
            LinkedList<Test.SmallStruct> l = new LinkedList<Test.SmallStruct>(smallStructArray);
            Test.SmallStructLinkedListHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            LinkedList<Test.SmallStruct> l2 = Test.SmallStructLinkedListHelper.read(@in);
            test(l2.Count == l.Count);
            IEnumerator<Test.SmallStruct> e = l.GetEnumerator();
            IEnumerator<Test.SmallStruct> e2 = l2.GetEnumerator();
            while (e.MoveNext() && e2.MoveNext())
            {
                test(e.Current.Equals(e2.Current));
            }
        }

        {
            long[] arr =
            {
                0x01,
                0x11,
                0x12,
                0x22
            };
            @out = new Ice.OutputStream(communicator);
            Stack<long> l = new Stack<long>(arr);
            Test.LongStackHelper.write(@out, l);
            byte[] data = @out.finished();
            @in = new Ice.InputStream(communicator, data);
            Stack<long> l2 = Test.LongStackHelper.read(@in);
            test(Compare(l2, l));
        }

        {
            float[] arr =
            {
                (float)1,
                (float)2,
                (float)3,
                (float)4
            };
开发者ID:externl,项目名称:ice,代码行数:67,代码来源:AllTests.cs

示例12: Clear_Wrapped

 public void Clear_Wrapped()
 {
     // Try to exercise special case of clearing when we've wrapped around
     var q = new Queue<string>(4);
     for (int i = 0; i < 4; i++)
     {
         q.Enqueue(i.ToString());
     }
     Assert.Equal("0", q.Dequeue());
     Assert.Equal("1", q.Dequeue());
     q.Enqueue("5");
     q.Enqueue("6");
     Assert.Equal(4, q.Count);
     q.Clear();
     Assert.Equal(0, q.Count);
     Assert.False(q.GetEnumerator().MoveNext());
 }
开发者ID:natemcmaster,项目名称:corefx,代码行数:17,代码来源:QueueTests.cs

示例13: Rollback

        public void Rollback()
        {
            if (transactedEntries != null && transactedEntries.Count > 0)
            {
                // make a list of non-transacted entries
                // @undone: bmalhi: transacted entries only on priority-0

                IEnumerator<SchedulableItem> e = this.normalPriorityEntriesQueue.GetEnumerator();
                Queue<SchedulableItem> newScheduled = new Queue<SchedulableItem>();
                while (e.MoveNext())
                {
                    if (!transactedEntries.Contains(e.Current))
                        newScheduled.Enqueue(e.Current);
                }

                // clear the scheduled items
                this.normalPriorityEntriesQueue.Clear();

                // schedule the non-transacted items back
                e = newScheduled.GetEnumerator();
                while (e.MoveNext())
                    this.normalPriorityEntriesQueue.Enqueue(e.Current);

                transactedEntries = null;
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:26,代码来源:Scheduler.cs

示例14: NegTest1

    public bool NegTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("NegTest1: InvalidOperationException should be thrown when the collection was modified after the enumerator was created.");

        try
        {
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            TestQueue.Enqueue("four");
            TestEnumerator.MoveNext();
            TestLibrary.TestFramework.LogError("N01.1", "InvalidOperationException is not thrown when the collection was modified after the enumerator was created!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("N01.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:31,代码来源:enumeratormovenext.cs

示例15: PosTest4

    public bool PosTest4()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("PosTest4: With a Queue that contains three items, MoveNext returns true the first three times and returns false every time it is called after that.");

        try
        {
            bool b;
            Queue<string> TestQueue = new Queue<string>();
            TestQueue.Enqueue("one");
            TestQueue.Enqueue("two");
            TestQueue.Enqueue("three");
            Queue<string>.Enumerator TestEnumerator;
            TestEnumerator = TestQueue.GetEnumerator();
            for (int i = 0; i < 3; i++)
            {
                b = TestEnumerator.MoveNext();
                if (!b)
                {
                    TestLibrary.TestFramework.LogError("P04.1", "MoveNext() failed!");
                    retVal = false;
                }
            }
            b = TestEnumerator.MoveNext();
            if (b)
            {
                TestLibrary.TestFramework.LogError("P04.1", "MoveNext() failed!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P04.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogVerbose(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:39,代码来源:enumeratormovenext.cs


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