本文整理汇总了C#中Deque.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Deque.GetEnumerator方法的具体用法?C# Deque.GetEnumerator怎么用?C# Deque.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deque
的用法示例。
在下文中一共展示了Deque.GetEnumerator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEnumerator
public void TestEnumerator()
{
var exp = new int[] { 0, 1, 2, 3, 4, 5 };
var d = new Deque<int>(4);
d.AddLast(0);
d.AddLast(1);
d.AddLast(2);
d.AddLast(3);
d.AddLast(4);
d.AddLast(5);
int index = 0;
foreach (var i in d) {
Assert.IsTrue(i == exp[index++]);
}
Assert.IsTrue(index == 6);
index = 0;
var en = d.GetEnumerator();
while (en.MoveNext()) {
Assert.IsTrue(en.Current == exp[index++]);
}
Assert.IsTrue(index == 6);
}
示例2: GetEnumeratorExample
public void GetEnumeratorExample()
{
var deque = new Deque<string>();
deque.EnqueueHead("cat");
deque.EnqueueHead("dog");
deque.EnqueueHead("dog");
deque.EnqueueHead("canary");
// Get the enumerator and iterate through it.
var enumerator = deque.GetEnumerator();
while (enumerator.MoveNext())
{
Debug.WriteLine(enumerator.Current);
}
}
示例3: TestEnumerator
private static void TestEnumerator(Deque deque)
{
deque.Clear();
PopulateDequePushBack(deque);
IEnumerator e = deque.GetEnumerator();
try
{
//object obj = e.Current;
UnityEngine.Debug.LogError("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
foreach(object obj in deque)
{
System.Diagnostics.Debug.Assert(e.MoveNext());
}
System.Diagnostics.Debug.Assert(!e.MoveNext());
//object o = e.Current;
UnityEngine.Debug.LogError("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
e.Reset();
foreach(object obj in deque)
{
System.Diagnostics.Debug.Assert(e.MoveNext());
}
System.Diagnostics.Debug.Assert(!e.MoveNext());
//object o = e.Current;
UnityEngine.Debug.LogError("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
deque.PushBack(deque.Count);
e.Reset();
UnityEngine.Debug.LogError("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
e.MoveNext();
UnityEngine.Debug.LogError("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
示例4: TestEnumerator
private static void TestEnumerator(Deque deque)
{
deque.Clear();
PopulateDequePushBack(deque);
IEnumerator e = deque.GetEnumerator();
try
{
object obj = e.Current;
Debug.Fail("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
foreach(object obj in deque)
{
Debug.Assert(e.MoveNext());
}
Debug.Assert(!e.MoveNext());
object o = e.Current;
Debug.Fail("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
e.Reset();
foreach(object obj in deque)
{
Debug.Assert(e.MoveNext());
}
Debug.Assert(!e.MoveNext());
object o = e.Current;
Debug.Fail("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
deque.PushBack(deque.Count);
e.Reset();
Debug.Fail("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
e.MoveNext();
Debug.Fail("Exception failed");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}