GetEnumerator() public method

public GetEnumerator ( ) : IEnumerator
return IEnumerator
Beispiel #1
0
        public static void GetEnumerator_FromEmptyStack()
        {
            int[] operands = new int[] { };
            Stack<int> operandStack = new Stack<int>((IEnumerable<int>)operands);
            int[] expectedValues = new int[] { };

            Stack<int>.Enumerator enumerator = operandStack.GetEnumerator();
            Assert.True(HelperClass.VerifyEnumerator(enumerator, expectedValues)); //"Faild to get enumerator of an empty stack"
        }
Beispiel #2
0
        public static void GetEnumerator_FromNonEmptyStack()
        {
            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 };

            Stack<int>.Enumerator enumerator = operandStack.GetEnumerator();
            Assert.True(HelperClass.VerifyEnumerator(enumerator, expectedValues)); //"Faild to get enumerator of stack"
        }
 static public int GetEnumerator(IntPtr l)
 {
     try {
         System.Collections.Stack self = (System.Collections.Stack)checkSelf(l);
         var ret = self.GetEnumerator();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int GetEnumerator(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.Collections.Stack       obj = (System.Collections.Stack)ToLua.CheckObject(L, 1, typeof(System.Collections.Stack));
         System.Collections.IEnumerator o   = obj.GetEnumerator();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 private static int NToTen(string data, int n)
 {
     char[] key = new char[36] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
     string temp;
     int k = 0;
     int returnValue = 0;
     Stack s = new Stack();
     temp = data;
     for (int i = 0; i < temp.Length; i++)
     {
         for (int j = 0; j < key.Length; j++)
         {
             if (key[j] == data[i])
             {
                 s.Push(j);
             }
         }
     }
     IEnumerator myEnumerator = s.GetEnumerator();
     while (myEnumerator.MoveNext())
     {
         returnValue += int.Parse((int.Parse(myEnumerator.Current.ToString()) * Math.Pow(n, k)).ToString());
         k++;
     }
     return returnValue;
 }
 /// <summary>
 /// 将十进制转换为N进制
 /// </summary>
 /// <param name="data">十进制数</param>
 /// <param name="n">进制</param>
 /// <returns>N进制</returns>
 private static string TenToN(int data, int n)
 {
     char[] key = new char[36] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
     int temp;
     string returnValue = "";
     Stack s = new Stack();
     temp = data;
     do
     {
         s.Push(temp % n);
         temp = temp / n;
     }
     while (temp > 0);
     IEnumerator myEnumerator = s.GetEnumerator();
     while (myEnumerator.MoveNext())
     {
         returnValue += key[int.Parse(myEnumerator.Current.ToString())].ToString();
     }
     return returnValue;
 }
    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; });
    }
    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; });
    }
    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);
    }
        /// <summary>
        /// Suppression d'un Cours 
        /// dans une des piles de modification (toInsert ou toDelete)
        /// </summary>
        /// <param name="s"></param>
        /// <param name="dc_toRemove"></param>
        private void removeFromStack(Stack<Data_Cours> s, Data_Cours dc_toModify)
        {
            IEnumerator en = s.GetEnumerator();
            Data_Cours dc_current;

            en.Reset();

            // !!!!!!! l'énumérateur ne supporte pas que la collection soit modifiée !
            if (dc_toModify != null)
            {
                while (en.MoveNext())
                {
                    dc_current = (Data_Cours)en.Current;
                    // si dans la pile, on le supprime
                    if (dc_current.id == dc_toModify.id)
                    {
                        s.Pop();
                    }
                }
            }
        }
 /// <summary>
 /// Affichage d'une pile dans un TextBox de debug
 /// </summary>
 /// <param name="s"></param>
 private void debug_displayStack(Stack<Data_Cours> s)
 {
     IEnumerator en = s.GetEnumerator();
     Data_Cours dc_current;
     en.Reset();
     while (en.MoveNext())
     {
         dc_current = (Data_Cours)en.Current;
         if (dc_current != null)
         {
             tbx_debug.Text += dc_current.ToString() + "\t | ";
         }
     }
 }
Beispiel #12
0
 public override IEnumerator GetEnumerator()
 {
     lock (_root) {
         return(_s.GetEnumerator());
     }
 }