Add Elements to an Array Using the Extension Method and List in C# – Programming, Pseudocode Example, C# Programming Example
C# C# Console

Add Elements to an Array Using the Extension Method and List in C#

In this article, i’ll show you how to add new elements to an array in C#. We use the Extension method and List in C# to achieve this. This extension method is a generic method so we can pass any array type to append the element.

In C#, we have multiple ways to add elements to an array. In this blog, we will see how to add an element to an array using the Extension method and List<T> in C#. This extension method is a generic method so we can pass any array type to append the element.

Using this method, first, we will have to convert an array into the List, once converted then will append the new element to the end of the list. Finally, convert the list to an array and return.

In the below example, we will add the int type element to an array,

Output

In the below example, we will add the string type element to an array,

Output

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.