I'm aware that this would probably never be used in real life, but say I had a bunch of names objects instantiated from the class Student. I.e. I know that the names of my Student objects are "s1, s2, s3" and I want to add these into a List of Students (using a loop), not their fields, but the objects themselves. Again, I want to stress that in general it would never make sense to do this, of course a container would be better. I know this is totally incorrect syntax, but the idea I'm trying to capture is:
Student s1 = new Student(3434,"John Smith");
Student s2 = new Student(5454, "Sam Wilkies");
Student s3 = new Student(7878, "Jim Jam");
List<Student> students= new List<Student>();
for(int i; i<=3; i++){
string j= "s" + i.ToString();
students.add(Student[j]);
Like I said I know this is totally incorrect syntax. I thought maybe I could use Activator.CreateInstance (which everyone says to avoid using), but I couldn't figure it out.