There was a problem saving a dynamic list whose elements are class objects. Namely, I can not understand where to place the created list of objects - in a static class as a class field, in a public class as a class field.
Why did this problem arise? From it follows another, namely: a partially repeated class name. It is necessary to create 2 classes - class Object and class Objects. I write: Object obj = new Object() in the first case and Objects objs = new Objects() . Is this correct? I saw on YouTube that they are doing this, but they do not explain why. All I want to know is if I use the correct approach (I describe the class of a single object, and then a group of objects, if I have to), or is something different used?
Here, sketched a working code, if someone did not understand my fears:
public class Program { static void Main(string[] args) { var students = new Students(); for (int i = 0; i < 10; i++) { students.StudentList.Add(new Student() { FirstName = "Vladislav", LastName = "Volkov", Age = 24 }); } Console.ReadKey(); } public class Student { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } public class Students { public List<Student> StudentList; public Students() { StudentList = new List<Student>(); } } } }