+ 1

Create object in for loop? (C#)

I want to create a object but several times just like this: for (int Zero; Zero < VarCounter; Zero++;) { Class Sub = new Class(); } But I need to create various "Sub" with different names, how can I do that?

14th May 2018, 10:26 PM
SebGM2018
SebGM2018 - avatar
2 Answers
+ 3
Perhaps use an array: Class arr = new Class[VarCounter]; for (int Zero; Zero < arr.length; Zero++) arr[Zero] = new Class();
14th May 2018, 10:46 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
Thanks!
14th May 2018, 10:46 PM
SebGM2018
SebGM2018 - avatar