本文整理汇总了C#中System.Collections.Stack.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.GetEnumerator方法的具体用法?C# Stack.GetEnumerator怎么用?C# Stack.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Stack
的用法示例。
在下文中一共展示了Stack.GetEnumerator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnumerator_FromEmptyStack
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"
}
示例2: GetEnumerator_FromNonEmptyStack
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"
}
示例3: NToTen
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;
}
示例4: TenToN
/// <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;
}
示例5: 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; });
}
示例6: 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; });
}
示例7: 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);
}
示例8: removeFromStack
/// <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();
}
}
}
}
示例9: debug_displayStack
/// <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 | ";
}
}
}