C#: How can I dynamically create an array in c#

In c# we can create dynamic array If we don’t know exact size of array. We will create array with the help of list below I have given code.


// Create List first
List<string> stringList = new List<string>();

// Add item into list
stringList.Add("1");
stringList.Add("2");
stringList.Add("3");

//Assign string list to array
string[] stringArray = stringList.ToArray();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s