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

Published on February 15, 2017 by abundantcode

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: 0 (0 votes)

This article have been viewed 3342 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


x

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...