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


C# Stack.GetEnumerator方法代码示例

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


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "P001";
        string c_TEST_DESC = "PosTest1: Get enumerator from non-empty stack.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        int[] operands = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
        int[] expectedValues = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            enumerator = operandStack.GetEnumerator();
            if (!this.VerifyEnumerator(enumerator, expectedValues))
            {
                errorDesc = "Faild to get enumerator of stack. The stack is " +
                    this.GetStackData(operandStack);
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe stack is " + GetStackData(operandStack);
            TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

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

示例2: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        string c_TEST_DESC = "PosTest2: Move the enumerator of empty stack.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        Stack<int> operandStack = new Stack<int>();
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            enumerator = operandStack.GetEnumerator();
            retVal = this.VerifyEnumerator(c_TEST_ID, enumerator, new int[] { });
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe stack is " + GetStackData(operandStack);
            TestLibrary.TestFramework.LogError(c_TEST_ID + ".3", errorDesc);
            retVal = false;
        }

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

示例3: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "P001";
        string c_TEST_DESC = "PosTest1: Release resources used by enumerator of non-empty stack.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        int[] operands = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            enumerator = operandStack.GetEnumerator();
            enumerator.Dispose();
            if (enumerator.MoveNext())
            {
                errorDesc = "Failed to release resources used by the stack enumerator. The stack is " +
                    this.GetStackData(operandStack);
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe stack is " + GetStackData(operandStack);
            TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

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

示例4: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "P001";
        string c_TEST_DESC = "PosTest1: Get the element at the current position of the enumerator from non-empty stack.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        int[] operands = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            int[] expectedValues = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
            enumerator = operandStack.GetEnumerator();
            retVal = this.VerifyEnumerator(c_TEST_ID, enumerator, expectedValues);
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe stack is " + GetStackData(operandStack);
            TestLibrary.TestFramework.LogError(c_TEST_ID + ".3", errorDesc);
            retVal = false;
        }

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

示例5: PrintStack

 private static void PrintStack(Stack<int> stack)
 {
     var e = stack.GetEnumerator();
     bool empty = true;
     while (e.MoveNext())
     {
         empty = false;
         Console.Write(e.Current + " ");
     }
     if (empty)
     {
         Console.WriteLine("empty");
     } else
     {
         Console.WriteLine();
     }
 }
开发者ID:slao-learn,项目名称:epi,代码行数:17,代码来源:P16_1.cs

示例6: NegTest1

    public bool NegTest1()
    {
        bool retVal = true;

        const string c_TEST_ID = "N001";
        string c_TEST_DESC = "NegTest1: The collection was modified after the enumerator was created.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        Stack<int> operandStack = new Stack<int>();
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            enumerator = operandStack.GetEnumerator();
            operandStack.Push(1);
            enumerator.MoveNext();
            errorDesc = "InvalidOperationException is not thrown as expected when the collection was modified after the enumerator was created.";
            TestLibrary.TestFramework.LogError(c_TEST_ID + ".1", errorDesc);
            retVal = false;
        }
        catch (InvalidOperationException)
        { }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe collection was modified after the enumerator was created.";
            TestLibrary.TestFramework.LogError(c_TEST_ID + ".2", errorDesc);
            retVal = false;
        }

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

示例7: 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

示例8: EnumeratingBeyondEndOfListThenGetObject

    public static void EnumeratingBeyondEndOfListThenGetObject()
    {
        Stack stack = new Stack();
        stack.Push(new Object());
        stack.Push(stack);

        IEnumerator ienum = stack.GetEnumerator();

        Assert.True(ienum.MoveNext());

        for (int i = 0; i < 100; i++)
        {
            Object objTemp1 = ienum.Current;
            Assert.True(objTemp1.Equals(stack));
        }

        Assert.True(ienum.MoveNext());

        for (int i = 0; i < 100; i++)
        {
            Assert.False(ienum.MoveNext());
        }

        Assert.Throws<InvalidOperationException>(() => { var o = ienum.Current; });
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:25,代码来源:StackBasicTests.cs

示例9: GetBeforeStartingEnumerator

    public static void GetBeforeStartingEnumerator()
    {
        // NOTE: The docs say this behaviour is undefined so if test fails it might be ok
        Stack stack = new Stack();
        stack.Push("a");
        stack.Push("b");

        IEnumerator ienum = stack.GetEnumerator();
        Assert.Throws<InvalidOperationException>(() => { Object obj = ienum.Current; });
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:StackBasicTests.cs

示例10: GettingEnumeratorAndLoopingThroughWorks

    public static void GettingEnumeratorAndLoopingThroughWorks()
    {
        Stack stack = new Stack();
        stack.Push("hey");
        stack.Push("hello");

        IEnumerator ienum = stack.GetEnumerator();
        int iCounter = 0;

        while (ienum.MoveNext())
        {
            iCounter++;
        }

        Assert.Equal(iCounter, stack.Count);
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:16,代码来源:StackBasicTests.cs

示例11: GetCommands

 List<IUndoableCommand> GetCommands(Stack<IUndoableCommand> commands, int count)
 {
     List<IUndoableCommand> items = new List<IUndoableCommand>();
       if(count < 0)
     count = items.Count;
       IEnumerator<IUndoableCommand> enumerator = commands.GetEnumerator();
       for(int i = 0; i < count && enumerator.MoveNext(); i++)
     items.Add(enumerator.Current);
       return items;
 }
开发者ID:calvinkwong,项目名称:pol-the-game,代码行数:10,代码来源:CommandHandler.cs

示例12: runTest


//.........这里部分代码省略.........
                {
                    ++iCountErrors;
                    Console.WriteLine( "Err_015b,  Expected ArgumentException but exception thrown= " + ex.ToString() );
                }
            }
            strLoc = "Loc_Tst0015";
            if ( verbose ) Console.WriteLine( "copy should throw because of outofrange" );
            try
            {
                ++iCountTestcases;
                stack = new Stack();
                stack.Push( "MyString" );
                objArr = new Object[0];
                stack.CopyTo( objArr, 0 );
                ++iCountErrors;
                Console.WriteLine( "Err_016a,  Expected ArgumentException but no exception thrown" );
            }
            catch ( ArgumentException )
            {
            }
            catch (Exception ex)
            {
                ++iCountErrors;
                Console.WriteLine( "Err_016b,  Expected ArgumentException but exception thrown= " + ex.ToString() );
            }
            strLoc = "Loc_Tst0017";
            if ( verbose ) Console.WriteLine( "get enumerator and loop through" );
            try
            {
                ++iCountTestcases;
                stack = new Stack();
                stack.Push( "hey" );
                stack.Push( "hello" );
                IEnumerator ienum = stack.GetEnumerator();
                int iCounter = 0;
                while ( ienum.MoveNext() )
                {
                    iCounter++;
                }
                if ( iCounter != stack.Count )
                {
                    ++iCountErrors;
                    Console.WriteLine( "Err_017a,  did not enumerate though enough elements" );
                }
            }
            catch (Exception ex)
            {
                ++iCountErrors;
                Console.WriteLine( "Err_017b,  Expected noexception but exception thrown= " + ex.ToString() );
            }
            strLoc = "Loc_Tst0018";
            if ( verbose ) Console.WriteLine( "get before starting enumerator" );
            try
            {
                ++iCountTestcases;
                stack = new Stack();
                stack.Push( "a" );
                stack.Push( "b" );
                IEnumerator ienum = stack.GetEnumerator();
                Object obj = ienum.Current;
                ++iCountErrors;
                Console.WriteLine( "Err_018a,  should have thrown InvalidOperationException" );
            }
            catch ( InvalidOperationException )
            {}
            catch (Exception ex)
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:67,代码来源:co1726allsigns_stack_copycat.cs

示例13: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        string c_TEST_DESC = "PosTest2: Get enumerator from empty stack.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        Stack<int> operandStack = new Stack<int>();
        int[] expectedValues = new int[] {};
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            enumerator = operandStack.GetEnumerator();
            if (!this.VerifyEnumerator(enumerator, expectedValues))
            {
                errorDesc = "Faild to get enumerator of stack. The stack is emtpy.";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e + "\nThe stack is empty.";
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

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

示例14: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        string c_TEST_DESC = "PosTest2: Release resources used by enumerator of empty stack.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        Stack<int> operandStack = new Stack<int>();
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            enumerator = operandStack.GetEnumerator();
            enumerator.Dispose();
            if (enumerator.MoveNext())
            {
                errorDesc = "Failed to release resources used by the stack enumerator. The stack is emtpy.";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e + "\nThe stack is empty.";
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

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

示例15: NegTest2

    public bool NegTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "N002";
        string c_TEST_DESC = "NegTest2: The enumerator is positioned after the last element of the collection.";
        string errorDesc;

        Stack<int>.Enumerator enumerator;
        Stack<int> operandStack = new Stack<int>();
        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            operandStack.Push(1);
            enumerator = operandStack.GetEnumerator();
            for (int i = 0; i <= operandStack.Count; ++i)
            {
                enumerator.MoveNext();
            }
            int val = enumerator.Current;
            errorDesc = "InvalidOperationException is not thrown as expected when The enumerator is positioned before the last element of the collection.";
            TestLibrary.TestFramework.LogError(c_TEST_ID + ".1", errorDesc);
            retVal = false;
        }
        catch (InvalidOperationException)
        { }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e +
                "\nThe enumerator is positioned before the last element of the collection.";
            TestLibrary.TestFramework.LogError(c_TEST_ID + ".2", errorDesc);
            retVal = false;
        }

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


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