当前位置: 首页>>代码示例>>C#>>正文


C# DynamicArray.Resize方法代码示例

本文整理汇总了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());
 }
开发者ID:Sinbadsoft,项目名称:Sinbadsoft.Lib.Collections,代码行数:16,代码来源:ResizeInsertTests.cs

示例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));
       }
开发者ID:Sinbadsoft,项目名称:Sinbadsoft.Lib.Collections,代码行数:36,代码来源:DynamicArrayExceptionsTests.cs

示例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);
        }
开发者ID:Sinbadsoft,项目名称:Sinbadsoft.Lib.Collections,代码行数:60,代码来源:ResizeInsertTests.cs


注:本文中的DynamicArray.Resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。