本文整理汇总了C#中DynamicArray.Resize方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicArray.Resize方法的具体用法?C# DynamicArray.Resize怎么用?C# DynamicArray.Resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray.Resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ExceptionOnIncorrectIndexesSize
public static void ExceptionOnIncorrectIndexesSize()
{
var dynArray = new DynamicArray<int>(3);
var tooLargeIndexes = new int[dynArray.Rank + 1];
var tooSmallIndexes = new int[dynArray.Rank - 1];
// Indexer get
Assert.Throws<ArgumentException>(() => { int i = dynArray[tooSmallIndexes]; });
Assert.Throws<ArgumentException>(() => { int i = dynArray[tooLargeIndexes]; });
// Indexer set
Assert.Throws<ArgumentException>(() => dynArray[tooLargeIndexes] = 10);
Assert.Throws<ArgumentException>(() => dynArray[tooSmallIndexes] = 10);
// GetValue
Assert.Throws<ArgumentException>(() => { int i = dynArray.GetValue(tooSmallIndexes); });
Assert.Throws<ArgumentException>(() => { int i = dynArray.GetValue(tooLargeIndexes); });
// SetValue
Assert.Throws<ArgumentException>(() => dynArray.SetValue(10, tooLargeIndexes));
Assert.Throws<ArgumentException>(() => dynArray.SetValue(10, tooSmallIndexes));
// Insert
Assert.Throws<ArgumentException>(
() => dynArray.Insert(new[,,] { { { 1 }, { 2 } }, { { 1 }, { 2 } } }, 0, tooSmallIndexes));
Assert.Throws<ArgumentException>(
() => dynArray.Insert(new[,,] { { { 1 }, { 2 } }, { { 1 }, { 2 } } }, 0, tooLargeIndexes));
// Resize
Assert.Throws<ArgumentException>(() => dynArray.Resize(tooLargeIndexes));
Assert.Throws<ArgumentException>(() => dynArray.Resize(tooSmallIndexes));
// Extend
Assert.Throws<ArgumentException>(() => dynArray.Extend(tooLargeIndexes));
Assert.Throws<ArgumentException>(() => dynArray.Extend(tooSmallIndexes));
}
示例3: Resize2D
public static void Resize2D()
{
// Should have B_COLS < A_COLS
const int A_ROWS = 4;
const int A_COLS = 3;
const int B_ROWS = 5;
const int B_COLS = 2;
// Arrays O, A and B
object[,] arrA = ArrayHelper.New().NewArray<object>(A_ROWS, A_COLS).FillWith("A").As<object[,]>();
object[,] arrB = ArrayHelper.New().NewArray<object>(B_ROWS, B_COLS).FillWith("B").As<object[,]>();
// NOTE capacities are set to the minimum to force buffer resize
DynamicArray<object> dynArray = new DynamicArray<object>(2, 1, 1);
// Insert B at 0,0
dynArray.Insert(arrB, 0, 0, 0);
ArrayHelper.Print(dynArray);
DynamicArrayAssert.AreElementsEqual(dynArray, arrB);
// Insert A right before B in dim 1
dynArray.Insert(arrA, 0, 0, 0);
ArrayHelper.Print(dynArray);
DynamicArrayAssert.Included(dynArray, arrA, 0, 0);
DynamicArrayAssert.Included(dynArray, arrB, A_ROWS, 0);
DynamicArrayAssert.CountsEqual(dynArray, A_ROWS + B_ROWS, A_COLS);
// Remove B_ROWS lines and add NCols columns
const int NCols = 5;
dynArray.Resize(A_ROWS, A_COLS + NCols);
ArrayHelper.Print(dynArray);
DynamicArrayAssert.Included(dynArray, arrA, 0, 0);
DynamicArrayAssert.AreElementsDefault(dynArray, new int[] { A_ROWS, NCols }, 0, A_COLS);
DynamicArrayAssert.CountsEqual(dynArray, A_ROWS, A_COLS + NCols);
// Add NRows rows
const int NRows = 10;
dynArray.ResizeDim(0, A_ROWS + NRows);
ArrayHelper.Print(dynArray);
DynamicArrayAssert.CountsEqual(dynArray, A_ROWS + NRows, A_COLS + NCols);
DynamicArrayAssert.Included(dynArray, arrA, 0, 0);
DynamicArrayAssert.AreElementsDefault(dynArray, new int[] { NRows, A_COLS + NCols }, A_ROWS, 0);
DynamicArrayAssert.AreElementsDefault(dynArray, new int[] { A_ROWS + NRows, NCols }, 0, A_COLS);
// Shrink to (NFewRows, NFewCols)
const int NFewCols = 2;
const int NFewRows = 3;
dynArray.Resize(NFewRows, NFewCols);
ArrayHelper.Print(dynArray);
DynamicArrayAssert.Included(dynArray, arrA, Zero2DIdx, Zero2DIdx, new int[] { NFewRows, NFewCols });
// Enlarge to (NManyRows, NManyCols)
const int NManyRows = 10;
const int NManyCols = 7;
dynArray.Resize(NManyRows, NManyCols);
ArrayHelper.Print(dynArray);
DynamicArrayAssert.Included(dynArray, arrA, Zero2DIdx, Zero2DIdx, new int[] { NFewRows, NFewCols });
DynamicArrayAssert.AreElementsDefault(dynArray, new[] { NManyRows, NManyCols - NFewCols }, 0, NFewCols);
DynamicArrayAssert.AreElementsDefault(dynArray, new[] { NManyRows - NFewRows, NFewCols }, NFewRows, 0);
}