Dynamics arrays are array which size is not fixed, you can add value on front, back and use some functions to make your code project easier
First to use the dynamic array download the .cs file and add it to your C# project Add the using part to enemble dynamics arrays in your project
using DynamicArray;
To create an dynamic array use the next C# line
DynamicArray<type> array = new DynamicArray<type>(size);
< type > : the type is the type of values inside the array
array : is the array name
size : is the default size in int type, if you don't know what size you need use 0 as a empty array
-
Push_front and push_back functions
array.PushFront(value1);
Add the value1 at the front of the array
array.PushBack(value2);
Add the value2 at the back of the array -
Insert function
array.Insert(index, value);
Set the value at index index for value
array.Insert(-1, value);
Set the value at the last index for value -
Size property and clear functions
array.Size;
Return the size of the array
array.Clear();
Reset the array to size 0 and erase all values -
Remove functions
array.Remove(index);
Erase the value at the index from the array
array.Remove(indexstart, indexend);
Erase all values from indexstart to indexend, including the values at indexstart and indexend
array.Remove(indexstart, -1);
Erase all values from indexstart to the end of the array, including the values at indexstart and the last value -
At functions
array.At(index);
Return the value at the index -
Fill functions
array.Fill(indexstart, indexend, value);
Replace all index in array from indexstart to indexend by the value, including the indexstart and indexend -
Copy and sort functions
array.Copy(array2);
Copy the array2 to the array
array.Sort();
Sort the array -
Reverse functions
array.Reverse();
Return the reversed array -
Find functions
array.Find(value);
Return the first index of the value -
Add functions
array.Add(array2);
Add the array2 to the array
using System;
using DynamicArray;
namespace Test
{
internal class Program
{
static void Main(string[] args)
{
DynamicArray<int> array = new DynamicArray<int>(5);
for (int i = 0; i < array.Size; i++)
array.Insert(i, i);
DynamicArray<int> array2 = new DynamicArray<int>(0);
array2.Copy(array);
array2.Add(array);
array2.Sort();
array2.Reverse();
array2.Remove(6, -1);
array2.Fill(0, 1, -3);
array2.PushFront(-10);
array2.PushBack(100);
int index = array2.Find(-3);
Console.WriteLine(index);
for (int i = 0; i < array2.Size; i++)
{
Console.WriteLine(array2.At(i));
}
array2.Clear();
Console.WriteLine(array2.Size);
Console.ReadKey();
}
}
}
OUTPUT:
1
-10
-3
-3
3
3
2
2
100
0