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