How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below.

String[] strArray = new String[5];

Can we create an array without defining the size ?

The best option in this  scenario is to use the collection. You can use the Generic List which allows you to add as many items as possible and then you can use the ToArray method to convert to an array.

var lstrray = new List<string>();

string[] strArray = lstrray.ToArray();
Tags :

Leave Your Comment

Liked this content?. Please spread the word :)