當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。