本文整理汇总了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);
}
}
}
示例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]));
}
}
}
}