0

how to create multiple class objects using loop in main method so as not to define each object separately?

how to create multiple class objects using loop in main method so as not to define each object separately? Student tom = new Student { Name = "Tom" }; Student alice = new Student { Name = "Alice" }; Student bob = new Student { Name = "Bob" };

17th Jan 2022, 11:12 AM
Роман Жигунов
Роман Жигунов - avatar
6 ответов
+ 4
I can only think of using an array, although obviously objects then can only be referred to by index rather than unique identifier (variable names). Create a string array to contain the names. Create an array of Student instance, reserve as many elements as the names array. Use loop to initialize Student instances by the names in string array.
17th Jan 2022, 11:59 AM
Ipang
+ 2
But I'm not even sure that's what you asked for ...
17th Jan 2022, 12:35 PM
Ipang
+ 1
Ipang ,Thank you
17th Jan 2022, 1:37 PM
Роман Жигунов
Роман Жигунов - avatar
0
Ipang, can you write an example?
17th Jan 2022, 12:34 PM
Роман Жигунов
Роман Жигунов - avatar
0
Until I see, I won't know)
17th Jan 2022, 12:41 PM
Роман Жигунов
Роман Жигунов - avatar