Add new item in existing array in c.net
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In C#, an array has a fixed length once it is created. That means you cannot truly append a new element to the same array object. You either create a new array with more space, or you use a dynamic collection such as List<T> that is designed for growth.
Arrays Are Fixed Size
This is the core rule behind the question.
After creation, numbers.Length cannot be increased on that instance. Any operation that looks like "adding" to an array is really allocating a new array and copying values.
Use Array.Resize If You Must Keep An Array
If an API truly requires an array, Array.Resize is the simplest built-in option.
This works because Array.Resize creates a larger array internally, copies the old values, and updates the reference.
Manual Copying Shows What Is Really Happening
You can do the same operation explicitly.
This version is useful for understanding the cost: every append requires allocation and copying.
Prefer List<T> For Repeated Growth
If you are adding items repeatedly, List<T> is usually the correct data structure.
List<T> manages an internal array for you and grows capacity in chunks, which is much more efficient than resizing an array on every append.
If you later need an array, convert at the boundary:
That keeps most of your code on the collection type that actually matches the workflow.
When Arrays Still Make Sense
Arrays are still a good fit when the size is known in advance, performance is predictable, and random indexed access matters. They are not the wrong tool in general; they are just the wrong tool for repeated append-heavy workloads.
For example, reading a fixed-size buffer or storing a known number of pixel values is a natural array use case. Building a growable list of user selections is not.
Performance Tradeoffs
Resizing an array once is fine. Resizing it in a tight loop is expensive because each growth step copies all existing elements.
This works, but it is much slower than:
The second version is the one you usually want.
Common Pitfalls
The most common mistake is thinking an array can be extended in place. It cannot. Another is using Array.Resize in a loop that keeps appending one item at a time, which creates unnecessary copying overhead. Developers also sometimes keep everything as List<T> and never convert back to an array even when a downstream API requires one; the clean answer is to use ToArray() at that boundary. Finally, if several variables point to the same original array, remember that resizing reassigns the reference rather than mutating the old instance.
Summary
- C# arrays have fixed length and cannot truly grow in place.
- '
Array.Resizeworks by allocating a new array and copying data.' - Manual copying is equivalent, just more explicit.
- '
List<T>is the better choice when you need to add items repeatedly.' - Convert to an array only when an API or storage format actually requires it.

