本文整理汇总了C#中DynamicArray.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicArray.GetEnumerator方法的具体用法?C# DynamicArray.GetEnumerator怎么用?C# DynamicArray.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray.GetEnumerator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResizeWithSameSize
public void ResizeWithSameSize()
{
var darray = new DynamicArray<int>(1);
IEnumerator invalidated = darray.GetEnumerator();
Assert.AreEqual(0, darray.Count);
darray.Resize(100);
Assert.AreEqual(100, darray.Count);
Assert.Throws<InvalidOperationException>(() => invalidated.MoveNext());
IEnumerator notInvalidated = darray.GetEnumerator();
Assert.AreEqual(100, darray.Count);
darray.Resize(100);
Assert.AreEqual(100, darray.Count);
Assert.DoesNotThrow(() => notInvalidated.MoveNext());
}
示例2: InvalidateEnumerator
public void InvalidateEnumerator(
[ValueSource("InvalidateActions")]Action<DynamicArray<int>> invalidator)
{
// Build a DynamicArray
var darray = new DynamicArray<int>(2);
darray.Insert(new[,] { { 3, 2, 4, 5, 7 }, { -3, -2, -4, -5, -7 } }, 0, 0, 0);
// Get the IEnumerator<T>
var enumerator = darray.GetEnumerator();
// Advance on step and check current value
enumerator.MoveNext();
Assert.AreEqual(3, enumerator.Current);
// Invalidate the array
invalidator(darray);
// Current must *NOT* rhrow if invalidation is right after MoveNext
// see http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.aspx
Assert.AreEqual(3, enumerator.Current);
// Move the invalidated enumerator (InvalidOperationException expected)
Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());
// Reset the invalidated enumerator (InvalidOperationException expected)
Assert.Throws<InvalidOperationException>(enumerator.Reset);
}