當前位置: 首頁>>代碼示例>>C#>>正文


C# Array.Resize方法代碼示例

本文整理匯總了C#中System.Array.Resize方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.Resize方法的具體用法?C# Array.Resize怎麽用?C# Array.Resize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Array的用法示例。


在下文中一共展示了Array.Resize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ZeroSizeTest

 public void ZeroSizeTest()
 {
     using (var map = new MemoryMapStream())
     {
         using (var array = new Array<uint>(map, 0))
         {
             Assert.AreEqual(0, array.Length);
         }
         using (var array = new Array<uint>(map, 100))
         {
             array.Resize(0);
             Assert.AreEqual(0, array.Length);
         }
     }
 }
開發者ID:cmberryau,項目名稱:reminiscence,代碼行數:15,代碼來源:ArrayTests.cs

示例2: ResizeTests

        public void ResizeTests()
        {
            var randomGenerator = new System.Random(66707770); // make this deterministic 

            using (var map = new MemoryMapStream())
            {
                using (var array = new Array<uint>(map, 1000, 256, 256, 32))
                {
                    var arrayExepected = new uint[1000];

                    for (uint i = 0; i < 1000; i++)
                    {
                        if (randomGenerator.Next(4) >= 2)
                        { // add data.
                            arrayExepected[i] = i;
                            array[i] = i;
                        }
                        else
                        {
                            arrayExepected[i] = int.MaxValue;
                            array[i] = int.MaxValue;
                        }

                        Assert.AreEqual(arrayExepected[i], array[i]);
                    }

                    Array.Resize<uint>(ref arrayExepected, 335);
                    array.Resize(335);

                    Assert.AreEqual(arrayExepected.Length, array.Length);
                    for (int i = 0; i < arrayExepected.Length; i++)
                    {
                        Assert.AreEqual(arrayExepected[i], array[i]);
                    }
                }

                using (var array = new Array<uint>(map, 1000, 256, 256, 32))
                {
                    var arrayExpected = new uint[1000];

                    for (uint i = 0; i < 1000; i++)
                    {
                        if (randomGenerator.Next(4) >= 1)
                        { // add data.
                            arrayExpected[i] = i;
                            array[i] = i;
                        }
                        else
                        {
                            arrayExpected[i] = int.MaxValue;
                            array[i] = int.MaxValue;
                        }

                        Assert.AreEqual(arrayExpected[i], array[i]);
                    }

                    Array.Resize<uint>(ref arrayExpected, 1235);
                    var oldSize = array.Length;
                    array.Resize(1235);

                    Assert.AreEqual(arrayExpected.Length, array.Length);
                    for (int i = 0; i < arrayExpected.Length; i++)
                    {
                        Assert.AreEqual(arrayExpected[i], array[i], 
                            string.Format("Array element not equal at index: {0}. Expected {1}, found {2}",
                                i, array[i], arrayExpected[i]));
                    }
                }
            }
        }
開發者ID:cmberryau,項目名稱:reminiscence,代碼行數:70,代碼來源:ArrayTests.cs


注:本文中的System.Array.Resize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。