本文整理匯總了C#中DynamicArray.Add方法的典型用法代碼示例。如果您正苦於以下問題:C# DynamicArray.Add方法的具體用法?C# DynamicArray.Add怎麽用?C# DynamicArray.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DynamicArray
的用法示例。
在下文中一共展示了DynamicArray.Add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
public static void Main()
{
DynamicArray<string> arrey = new DynamicArray<string>();
arrey.Add("Pesho");
arrey.Add("Gosho");
Console.WriteLine(arrey.IndexOf("Pesho"));
Console.WriteLine(arrey.Contains("Gosho"));
Console.WriteLine(arrey.Contains("Ivan"));
arrey.Remove("Pesho");
arrey.InsertAt(1, "Pesho");
arrey.Clear();
Console.WriteLine(arrey.Capacity);
Console.WriteLine(arrey.Count);
arrey.Add("Ivo");
arrey[0] = "Gosho";
var newArrey = arrey.ToArray();
Console.WriteLine();
foreach (var item in arrey)
{
Console.WriteLine(item);
}
Console.WriteLine();
foreach (var item in newArrey)
{
Console.WriteLine(item);
}
}
示例2: Main
static void Main(string[] args)
{
var array = new DynamicArray<string>();
array.Add("Georgi");
array.Add("Nikolai");
Console.WriteLine(array.IndexOf("Nikolai"));
Console.WriteLine(array.Cointains("Kiril"));
array.Remove("Georgi");
array.InsertAt(1, "Ivan");
array.Clear();
Console.WriteLine(array.Capacity);
Console.WriteLine(array.Count);
array.Add("Stefan");
array.Add("Krum");
var arr = array.ToArray();
Console.WriteLine();
foreach (var item in array)
{
Console.WriteLine(item);
}
Console.WriteLine();
foreach (var item in arr)
{
Console.WriteLine(item);
}
}
示例3: AddMoreThanCapacityTest
public void AddMoreThanCapacityTest()
{
DynamicArray<int> Arr = new DynamicArray<int>(2);
Arr.Add(65);
Arr.Add(16);
Arr.Add(76);
Assert.AreEqual(Arr.Length, 3);
Assert.AreEqual(Arr.Capacity, 4);
Assert.AreEqual(Arr[2], 76);
}
示例4: AddTest
public void AddTest()
{
DynamicArray<int> testArr = new DynamicArray<int>(4);
testArr.Add(0);
testArr.Add(1);
testArr.Add(2);
testArr.Add(3);
Assert.AreEqual(testArr[0], 0);
Assert.AreEqual(testArr[1], 1);
Assert.AreEqual(testArr[2], 2);
Assert.AreEqual(testArr[3], 3);
}
示例5: AddRangeMoreThanCapacity
public void AddRangeMoreThanCapacity()
{
int[] a = { 28, 98, 89, 25, 43 };
DynamicArray<int> Arr = new DynamicArray<int>(2);
Arr.Add(68);
Arr.Add(73);
Arr.AddRange(a);
Assert.AreEqual(Arr.Length, 7);
Assert.AreEqual(Arr.Capacity, 8);
Assert.AreEqual(Arr[2], 28);
Assert.AreEqual(Arr[6], 43);
}
示例6: AddTest
public void AddTest()
{
DynamicArray<int> Arr = new DynamicArray<int>();
Arr.Add(23);
Assert.AreEqual(Arr.Length, 1);
Assert.AreEqual(Arr[0], 23);
}
示例7: RandomOperation
public void RandomOperation()
{
var r = new Random();
const int totalOperations = 10000;
var target = new DynamicArray<int>();
for (var i = 0; i < totalOperations; i++)
{
int oldCount = target.Count;
switch (r.Next(3))
{
case 0: // Add
var newItem = r.Next();
target.Add(newItem);
Assert.AreEqual(oldCount + 1, target.Count);
Assert.AreEqual(newItem, target[oldCount]);
break;
case 1: // Remove by index
if(oldCount == 0) goto case 0;
var indexToRemove = r.Next(oldCount - 1);
target.RemoveAt(indexToRemove);
Assert.AreEqual(oldCount - 1, target.Count);
break;
case 2: // Remove by element
if (oldCount == 0) goto case 0;
var itemToRemove = target[r.Next(oldCount - 1)];
target.Remove(itemToRemove);
Assert.AreEqual(oldCount - 1, target.Count);
break;
}
}
}
示例8: Main
static void Main(string[] args)
{
DynamicArray<string> test = new DynamicArray<string>();
// test.Add("a");
// test.Add("b");
// test.Add("b");
test.Add("c");
test.Add("a");
// test.Add("b");
// test.Add("b");
test.Add("c");
// test.Remove("b");
// test.Remove("b");
// test.Remove("b");
test.Remove("b");
test.Remove("a");
Console.WriteLine(test[1]);
test[1] = "fuck you";
Console.WriteLine(test[1]);
}
示例9: TestMethod1
public void TestMethod1()
{
try
{
DynamicArray<int> m1 = new DynamicArray<int>();
DynamicArray<int> m2 = new DynamicArray<int>(9);
int[] arr = new[] { 1, 2, 3, 4, 5 };
DynamicArray<int> m3 = new DynamicArray<int>(arr);
var a = m3.Length;
Assert.AreEqual(a, 5);
var b = m3.Capacity;
Assert.AreEqual(b, 5);
m3.Add(6);
var a1 = m3.Length;
Assert.AreEqual(a1, 6);
var b1 = m3.Capacity;
Assert.AreEqual(b1, 10);
int[] arr1 = new[] { 7, 8, 9, 10, 11, 12 };
m3.AddRange(arr1);
var a3 = m3.Length;
Assert.AreEqual(a3, 12);
var b3 = m3.Capacity;
Assert.AreEqual(b3, 20);
var flag1 = m3.Remove(7);
var a4 = m3.Length;
Assert.AreEqual(a4, 11);
Assert.AreEqual(flag1, true);
//m3.Insert(26,14); //Попытка вставить вне границ массива
m3.Insert(6, 7);
var b4 = m3[6];
Assert.AreEqual(b4, 7);
int k = 1;
foreach (var elem in m3)
{
var a5 = elem;
Assert.AreEqual(a5, k);
k++;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Assert.AreEqual(0, 1);
}
}
示例10: TestInsertMethod
public void TestInsertMethod()
{
DynamicArray<int> m3 = new DynamicArray<int>(9);
int[] arr = new[] { 1, 2, 3, 4, 5 };
foreach (var elem in arr)
{
m3.Add(elem);
}
m3.Insert(2, 9);
var a1 = m3[2];
Assert.AreEqual(a1, 9);
}
示例11: TestAddMethod
public void TestAddMethod()
{
DynamicArray<int> m2 = new DynamicArray<int>(9);
m2.Add(10);
var a2 = m2.Length;
Assert.AreEqual(a2, 1);
var b2 = m2.Capacity;
Assert.AreEqual(b2, 9);
var a3 = m2[0];
Assert.AreEqual(a3, 10);
}
示例12: TestMethod1
public void TestMethod1()
{
try
{
DynamicArray<int> arr1 = new DynamicArray<int>();
DynamicArray<int> arr2 = new DynamicArray<int>(20);
int[] arr3 = new[] { 1, 2, 3, 4, 5 };
DynamicArray<int> arr4 = new DynamicArray<int>(arr3);
var a = arr4.Length;
Assert.AreEqual(a, 5);
var b = arr4.Capacity;
Assert.AreEqual(b, 5);
arr4.Add(6);
var a1 = arr4.Length;
Assert.AreEqual(a1, 6);
var b1 = arr4.Capacity;
Assert.AreEqual(b1, 10);
int[] arr31 = new[] { 7, 8, 9, 10, 11, 12 };
arr4.AddRange(arr31);
var a3 = arr4.Length;
Assert.AreEqual(a3, 12);
var b3 = arr4.Capacity;
Assert.AreEqual(b3, 20);
var flag1 = arr4.Remove(7);
var a4 = arr4.Length;
Assert.AreEqual(a4, 11);
Assert.AreEqual(flag1, true);
arr4.Insert(6, 7);
var b4 = arr4[6];
Assert.AreEqual(b4, 7);
int k = 1;
foreach (var elem in arr4)
{
var a5 = elem;
Assert.AreEqual(a5, k);
k++;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Assert.AreEqual(0, 1);
}
}
示例13: TestAddMethodWithIncrease
public void TestAddMethodWithIncrease()
{
int[] arr = new[] { 1, 2, 3, 4, 5 };
DynamicArray<int> m3 = new DynamicArray<int>(arr);
m3.Add(10);
var a = m3.Length;
Assert.AreEqual(a, 6);
var b = m3.Capacity;
Assert.AreEqual(b, 10);
var a3 = m3[5];
Assert.AreEqual(a3, 10);
}
示例14: AddElements
public void AddElements()
{
const int totalElements = 10000;
var target = new DynamicArray<int>();
foreach (var i in Enumerable.Range(1, totalElements))
{
target.Add(i);
}
Assert.AreEqual(totalElements, target.Count);
for (var i = 0; i < totalElements; i++)
{
Assert.AreEqual(i+1, target[i]);
}
}
示例15: GetWalkableSuccessors
/// <summary>
/// Gets the walkable successors of the specified node.
/// </summary>
/// <param name="current">The current node.</param>
/// <param name="successorArray">The array to fill with successors.</param>
/// <returns>
/// All walkable successors of the node.
/// </returns>
protected override void GetWalkableSuccessors(IPathNode current, DynamicArray<IPathNode> successorArray)
{
_neighbours.Clear();
if (current.predecessor == null)
{
current.GetWalkableNeighbours(_neighbours, _unitProps, _cutCorners, false);
}
else if (current is IPortalNode)
{
current.GetWalkableNeighbours(successorArray, _unitProps, _cutCorners, false);
return;
}
else
{
var dirFromPredecessor = current.predecessor.GetDirectionTo(current);
PruneNeighbours(current, dirFromPredecessor);
}
var neighbourCount = _neighbours.count;
for (int i = 0; i < neighbourCount; i++)
{
var n = _neighbours[i];
if (n == null)
{
break;
}
var dirToNeighbour = current.GetDirectionTo(n);
var jp = Jump(current, dirToNeighbour);
if (jp != null)
{
successorArray.Add(jp);
}
}
}