Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ru.so
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Students studentsList = new Students(new List<Student>(){ new Student(1,"Вася Я.Я.",DateTime.Parse("10.10.1995"),"+380678838340"), new Student(2,"Гася Я.Я.",DateTime.Parse("10.10.1995"),"+380678838340"), new Student(3,"Дася Я.Я.",DateTime.Parse("10.10.1995"),"+380678838340"), }); studentsList.Display(); Console.Write("\n\n"); studentsList.Add(new Student(4,"Пася Я.Я.",DateTime.Parse("10.10.1995"),"+380678838340")); studentsList.Display(); Console.Write("\n\n"); studentsList.Update(4, new Student(4,"Рася Я.Я.",DateTime.Parse("10.10.1996"),"+380000000000")); studentsList.Display(); Console.Write("\n\n"); studentsList.Remove(4); studentsList.Display(); } public class Student { public string FIO; public DateTime Bithday; public string Phone; public int Id; public Student(int id,string FIO,DateTime bithday,string phone) { this.Id = id; this.FIO = FIO; this.Bithday = bithday; this.Phone = phone; } } public class Students { public List<Student> students; public Students(List<Student> students) { this.students = students; } public void Add(Student student) { students.Add(student); } public bool Update(int id, Student _student) { var student = students.FirstOrDefault(st => st.Id == id); if (student == null) { return false; } else { student.FIO = _student.FIO; student.Bithday = _student.Bithday; student.Phone = _student.Phone; return true; } } public void Remove(int id) { for (int i = 0 ; i < students.Count; i++) { if (students[i].Id == id) { students.RemoveAt(i); } } } public void Display() { students.ForEach(st => Console.Write(st.FIO + " " + st.Bithday + " " + st.Phone + "\n")); } } } }
run
|
edit
|
history
|
help
0
dateTime parsing
Fórum SO ➡ Merging 2 lists by Name and adding their Values, using LINQ ♦
438935
divisão
Hello Demo
Prime
Compress in C#
a6
Raise Meldings logikk
Lotto35Generator