C
C#2y ago
DayKnight

✅ Input into list (Console app)

Program I want the user to keep creating accounts, and then put them inside at list Example of what the student requires
Student Alex = new Student(1, "Mike", "Scmith", new DateTime(1971, 2, 23), 0);
Student Alex = new Student(1, "Mike", "Scmith", new DateTime(1971, 2, 23), 0);
Enrollment x = new();
x.Enrollments = new List<Enrollment>()
{
};

Console.WriteLine("Write students ID:");
Alex.StudentId = Console.ReadLine();
Console.WriteLine("Write FirstName");
Alex.FirstName Console.ReadLine();
Console.WriteLine("Write LastName");
Alex.LastName Console.ReadLine();
Console.WriteLine("Write BirthDate");
Alex.StudentId Console.ReadLine();
Enrollment x = new();
x.Enrollments = new List<Enrollment>()
{
};

Console.WriteLine("Write students ID:");
Alex.StudentId = Console.ReadLine();
Console.WriteLine("Write FirstName");
Alex.FirstName Console.ReadLine();
Console.WriteLine("Write LastName");
Alex.LastName Console.ReadLine();
Console.WriteLine("Write BirthDate");
Alex.StudentId Console.ReadLine();
Studen Class
public class Student : PersonalInformation
{
public Student(int studentId, string firstName, string lastName, DateTime dateoftime, int age) : base(firstName, lastName, age)
{
StudentId = studentId;
}


public int StudentId
{
get;
set;
}
public class Student : PersonalInformation
{
public Student(int studentId, string firstName, string lastName, DateTime dateoftime, int age) : base(firstName, lastName, age)
{
StudentId = studentId;
}


public int StudentId
{
get;
set;
}
I am just not sure how to make an entire new object containing the given information, what should I do?
3 Replies
Angius
Angius2y ago
Take the inputs first, then create a Student with that data, then save it in your list
var books = new List<Book>();
while (true)
{
var title = Console.ReadLine();
var isbn = Console.ReadLine();
var author = Console.ReadLine();
var book = new Book(title, isbn, author);
books.Add(book);
}
var books = new List<Book>();
while (true)
{
var title = Console.ReadLine();
var isbn = Console.ReadLine();
var author = Console.ReadLine();
var book = new Book(title, isbn, author);
books.Add(book);
}
Something along those lines
DayKnight
DayKnight2y ago
Ah okay, thanks. I'll try to see if I can get it to work, or else I will come back. Thanks! 👍 😄
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server
More Posts