Let's say I have a completely empty array
int num = 1;
int[] arr = new int[0];
I just want to add the variable num to the arrat in the next possible position, like the .Add function for lists in C#. How would I do this without having to specify where I put it, only what to put. I do not want to use any Lists, basically just how the .Add function works for lists, but for arrays
I tried just using the .Add function but that didn't work. This was my full code:
public class Program
{
    public static int[] MultiplyByLength(int[] arr)
    {
        int[] finallist = new int[0];
        int curnum = 0;
        foreach(int item in arr)
        {
            curnum = item * arr.Length;
            finallist.Add(curnum);
        }
        return(finallist);
    }
}
But, clearly, it didn't work. how would I make the finallist.Add(curnum) line to work?


I do not want to use any Listswhy? Is there an actual reason for this or just an assumption?List<T>stores items in an internal array anyway. When a new item is added and the array is full, a new array with double the size is allocated and the existing data copied over.List.Addalso does.Concatreturns anIEnumerable<T>.ToArray()internally adds items to a buffer with reallocation once it's empty. At least withList<T>(capacity)you can specify the expected size and avoid reallocations.Addto a list, it knows where to do the insert (if the capacity runs out, it resizes itself internally). Arrays have no concept of "next possible position"