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


C# DynamicArray.ResizeDim方法代码示例

本文整理汇总了C#中DynamicArray.ResizeDim方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicArray.ResizeDim方法的具体用法?C# DynamicArray.ResizeDim怎么用?C# DynamicArray.ResizeDim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DynamicArray的用法示例。


在下文中一共展示了DynamicArray.ResizeDim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExceptionOnInvalidDimension

        public static void ExceptionOnInvalidDimension()
        {
            DynamicArray<string> dynArray = new DynamicArray<string>(2);
            
            // ExtendDim
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.ExtendDim(dynArray.Rank + 1, 4));
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.ExtendDim(-1, 4));

            // ExtendDim
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.ResizeDim(dynArray.Rank + 1, 4));
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.ResizeDim(-1, 4));

            // ExtendDim
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.GetCapacity(dynArray.Rank + 1));
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.GetCapacity(-1));

            // ExtendDim
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.GetCount(dynArray.Rank + 1));
            Assert.Throws<IndexOutOfRangeException>(() => dynArray.GetCount(-1));
        }
开发者ID:Sinbadsoft,项目名称:Sinbadsoft.Lib.Collections,代码行数:20,代码来源:DynamicArrayExceptionsTests.cs

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