Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Array

How to create an array with an indefinite number of variables in C#?

3rd Jun 2019, 8:40 PM
DaSh
DaSh - avatar
2 Answers
+ 1
You cannot. You need to define the size of an array upon declaration. That the nature of a array. https://www.tutorialspoint.com/csharp/csharp_arrays.htm If you need to have list without a predefined size use a "list". https://csharp-station.com/Tutorial/CSharp/Lesson20
3rd Jun 2019, 9:03 PM
sneeze
sneeze - avatar
+ 1
Simple, you create a list! using System.Collections.*; List<datatype> indefinite = new List<datatype>(); indefinite.Add("test"); indefinite.Add("test2"); Replace <datatype> with the datatype of your choice! You can than remove, reverse, sort and use useful methods such as contains, ToArray, Exists etc
3rd Jun 2019, 9:05 PM
HNNX 🐿
HNNX 🐿 - avatar