本文整理匯總了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);
}