C# | How to insert an element in an Array? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report An array is a collection of items stored at contiguous memory locations. In this article, we will see how to insert an element in an array in C#. Let's say we have an array and we want to insert an element at a specific position in this array. Here's how to do it. First get the element to be inserted, say x Then get the position at which this element is to be inserted, say pos Create a new array with the size one greater than the previous size Copy all the elements from previous array into the new array till the position pos Insert the element x at position pos Insert the rest of the elements from the previous array into the new array after the pos CSharp // C# program to insert an // element in an array using System; public class GFG { // Main Method static public void Main() { int n = 10; int[] arr = new int[n]; int i; // initial array of size 10 for (i = 0; i < n; i++) arr[i] = i + 1; // print the original array for (i = 0; i < n; i++) Console.Write(arr[i] + " "); Console.WriteLine(); // element to be inserted int x = 50; // position at which element // is to be inserted int pos = 5; // create a new array of size n+1 int[] newarr = new int[n + 1]; // insert the elements from the // old array into the new array // insert all elements till pos // then insert x at pos // then insert rest of the elements for (i = 0; i < n + 1; i++) { if (i < pos - 1) newarr[i] = arr[i]; else if (i == pos - 1) newarr[i] = x; else newarr[i] = arr[i - 1]; } // print the updated array for (i = 0; i < n + 1; i++) Console.Write(newarr[i] + " "); Console.WriteLine(); } } Output: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 50 5 6 7 8 9 10 Comment More info C code_r Follow Improve Article Tags : C# CSharp-Arrays Explore IntroductionC# Tutorial 4 min read Introduction to .NET Framework 6 min read C# .NET Framework (Basic Architecture and Component Stack) 6 min read C# Hello World 2 min read Common Language Runtime (CLR) in C# 4 min read FundamentalsC# Identifiers 2 min read Data Types in C# 6 min read C# Variables 4 min read C# Literals 5 min read Operators in C# 7 min read C# Keywords 5 min read Control StatementsC# Decision Making (if, if-else, if-else-if ladder, nested if, switch, nested switch) 5 min read C# Switch Statement 4 min read Loops in C# 4 min read C# Jump Statements (Break, Continue, Goto, Return and Throw) 4 min read OOP ConceptsClass and Objects in C# 4 min read Constructors in C# 5 min read C# Inheritance 3 min read Encapsulation in C# 2 min read C# Abstraction 4 min read MethodsMethods in C# 4 min read Method Overloading in C# 4 min read C# | Method Parameters 7 min read Method Overriding in C# 7 min read Anonymous Method in C# 3 min read ArraysArrays in C# 6 min read Jagged Arrays in C# 4 min read Array Class in C# 5 min read How to Sort an Array in C# | Array.Sort() Method Set - 1 8 min read How to find the rank of an array in C# 2 min read ArrayListArrayList in C# 6 min read C# ArrayList Class 7 min read C# | Array vs ArrayList 2 min read StringStrings in C# 6 min read C# Verbatim String Literal - @ 5 min read C# String Class 9 min read C# StringBuilder 4 min read C# String vs StringBuilder 3 min read TupleC# Tuple 7 min read C# Tuple Class 3 min read C# ValueTuple 7 min read C# ValueTuple Struct 4 min read IndexersC# Indexers 4 min read C# Multidimensional Indexers 5 min read C# - Overloading of Indexers 3 min read Like