How to Add Element Dynamically into one Array in C#?


We all knows that ArrayList is having one Add() to do so…
But in case of array it’s some how triky…
Here is the Example to add one element into an existing array..

string[] str ={ "1", "2", "3" };
string[] newstr = new string[str.Length + 1];
str.CopyTo(newstr, 0);
newstr.SetValue("4", newstr.Length - 1);
str = newstr;

Try the above code and enjoy it…

How useful was this post?

Click on a star to rate it!

Leave a Reply

Your email address will not be published. Required fields are marked *