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" };
6 Answers
+ 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.
+ 2
But I'm not even sure that's what you asked for ...
+ 1
Ipang ,Thank you
0
Ipang, can you write an example?
0
Until I see, I won't know)