本文整理汇总了C#中ConcurrentQueue.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentQueue.GetEnumerator方法的具体用法?C# ConcurrentQueue.GetEnumerator怎么用?C# ConcurrentQueue.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentQueue
的用法示例。
在下文中一共展示了ConcurrentQueue.GetEnumerator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBigFix792038
public static void TestBigFix792038()
{
List<int> allItems = new List<int>();
for (int i = 0; i < 10; i++)
allItems.Add(i);
ConcurrentQueue<int> queue = new ConcurrentQueue<int>(allItems);
var e = queue.GetEnumerator();
queue.Enqueue(11);
int count = 0;
while (e.MoveNext())
{
count++;
}
if (count != 10)
{
Console.WriteLine("* GetEnumerator should take snapshot at time of invoke not when MoveNext() is called");
Assert.False(true, "Failed! GetEnumerator should take snapshot at the time of invoke ");
}
}
示例2: IEnumerable_GetAllExpectedItems
public void IEnumerable_GetAllExpectedItems()
{
IEnumerable<int> enumerable1 = new ConcurrentQueue<int>(Enumerable.Range(1, 5));
IEnumerable enumerable2 = enumerable1;
int expectedNext = 1;
using (IEnumerator<int> enumerator1 = enumerable1.GetEnumerator())
{
IEnumerator enumerator2 = enumerable2.GetEnumerator();
while (enumerator1.MoveNext())
{
Assert.True(enumerator2.MoveNext());
Assert.Equal(expectedNext, enumerator1.Current);
Assert.Equal(expectedNext, enumerator2.Current);
expectedNext++;
}
Assert.False(enumerator2.MoveNext());
Assert.Equal(expectedNext, 6);
}
}
示例3: TestBigFix792038
public static void TestBigFix792038()
{
List<int> allItems = new List<int>();
for (int i = 0; i < 10; i++)
allItems.Add(i);
ConcurrentQueue<int> queue = new ConcurrentQueue<int>(allItems);
var e = queue.GetEnumerator();
queue.Enqueue(11);
int count = 0;
while (e.MoveNext())
{
count++;
}
Assert.Equal(10, count);
}