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

Published on February 15, 2017 by Senthil Kumar

Filed under Uncategorized

Last modified February 15, 2017

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 3.3 (6 votes)

This article have been viewed 14781 times

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();

Leave a Comment


You might be Interested in these Posts

C Program to convert lower case string to upper case

Problem Statement Write a program in C to convert the given string from lower case to upper case. ...

How to decode a base64 string in C#?

Here's a sample code snippet demonstrating how you can easily decode a base64 encoded string in C#. ...

How to disable editing of items in a combo box in c#?

When working in Win forms using C# and especially when you use the combo box , you would have notice...