Не обновляется список пользователей - C#
Формулировка задачи:
У меня возникла проблема, в списке пользователей. Список не обновляется если в него зайти повторно, после того как удалил одного пользователя.помогите исправить. Что бы зайти в проге в мою проблему, нажмите 1, удалите одного из юзеров по паролю и зайдите туда ещё раз и увидите что он вернулся(юзер). Лист с пользователями находиться в методе delet.
using System; using System.Collections.Generic; using System.Text; using System.Linq; using System.Threading; namespace ConsoleApplication1 { public class User { public string name; public string surname; public string country; public string sex; //male or female public int age; public string mail; public string login; public decimal password; public User(string name, string surname, string country, string sex, int age, string mail, string login, decimal password) { this.name = name; this.surname = surname; this.country = country; this.sex = sex; this.age = age; this.mail = mail; this.login = login; this.password = password; } } public class server { public string servername; public string servercoutry; public string ip; public server(string servername, string servercoutry, string ip) { this.servername = servername; this.servercoutry = servercoutry; this.ip = ip; } } class Program { public static void changePassword() { Console.WriteLine("Enter your password"); string Pass = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter your new password"); string firstPass = Convert.ToString(Console.ReadLine()); if (Pass == firstPass) { do { Console.WriteLine("Your new password is the similar as your old one"); Console.WriteLine("Enter your new password"); firstPass = Convert.ToString(Console.ReadLine()); } while (Pass == firstPass); } Console.WriteLine("Enter your password one more time"); string secondPass = Convert.ToString(Console.ReadLine()); string lastPass; if (firstPass != secondPass) do { Console.WriteLine("It wasn't correct with you new pass! Enter your password one more time"); lastPass = Convert.ToString(Console.ReadLine()); ; } while (firstPass != lastPass); Console.WriteLine("Your password successfully saved"); } public static void changeLogin() { Console.WriteLine("Enter your login for changing"); string log = Convert.ToString(Console.ReadLine()); Console.WriteLine("Enter your new login"); string firstLog = Convert.ToString(Console.ReadLine()); if (log == firstLog) { do { Console.WriteLine("Your new login is the similar as your old one"); Console.WriteLine("Enter your new login"); firstLog = Convert.ToString(Console.ReadLine()); } while (log == firstLog); } Console.WriteLine("Enter your new login one more time"); string secondLog = Convert.ToString(Console.ReadLine()); string lastLog; if (firstLog != secondLog) { do { Console.WriteLine("It wasn't correct with you new login! Enter your login one more time"); lastLog = Convert.ToString(Console.ReadLine()); } while (firstLog != lastLog); } Console.WriteLine("Your login successfully saved"); } public static void dataLogin() { changeLogin(); changePassword(); } public static void Greeting() { Console.WriteLine("Hello, dude!"); } public static void AboutMe() { Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine("\t About servers"); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine("| Server name | | Server location | | IP |"); var Servers = new List<server>(); Servers.Add(new server("| Pentagon |","| Chili |","| 192.168.0.1:25025 |")); Servers.Add(new server("| Zone51 |", "| Nevada |", "| 245.12386.0.1:26721 |")); foreach (server i in Servers) { Console.WriteLine(i.servername + " " + i.servercoutry + " " + i.ip + " "); } } public static void delet() { var UsersList = new List<User>(); UsersList.Add(new User("Vlad", "Seleznev", "Ukraine", "Male", 17, "removed@mail.ru", "Seleznev12", 12345)); UsersList.Add(new User("Ruslan", "Molchanuk", "Ukraine", "Male", 18, "risegaming.com", "rise12", 123456)); UsersList.Add(new User("Alexander", "Aprelenko", "Estonia", "Male", 17, "qwerty.com", "apr12", 1234567)); UsersList.Add(new User("Andrey", "Tsaryk", "Ukraine", "Male", 21, "sayta.net", "and12", 12345678)); UsersList.Add(new User("Patrik", "Buravchuk", "Ukraine", "Male", 16, "negrinafiji.net", "pat12", 123456789)); UsersList.Add(new User("Vetrov", "Alexey", "Ukraine", "Male", 17, "vetroveletel.est", "vet12", 12)); UsersList.Add(new User("Alexandra", "Suvorova", "Ukraine", "Female", 18, "s.suvorova98", "suv12", 123)); UsersList.Add(new User("Piven", "Bogdan", "Ukraine", "Male", 16, "pityxi.com", "bog12", 1234)); Console.WriteLine("Name|Surname|Country |Sex|Age| |E-mail| |LogIn| |Pasword|"); Console.WriteLine("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); foreach (User i in UsersList) { Console.WriteLine(i.name + " " + i.surname + " " + i.country + " " + i.sex + " " + i.age + " " + i.mail + " " + i.login + " " + i.password); Console.WriteLine("-------------------------------------------------------------------------------"); } Console.WriteLine("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); decimal passwordfind; User use; do { Console.WriteLine("Введите пароль пользователя для удаления"); passwordfind = Convert.ToDecimal(Console.ReadLine()); use = UsersList.FirstOrDefault(x => x.password.Equals(passwordfind)); if (use == null) { Console.WriteLine("Пользователя с таким паролем не существует"); } else UsersList.Remove(use); } while (use == null); foreach (User i in UsersList) { Console.WriteLine(i.name + " " + i.surname + " " + i.country + " " + i.sex + " " + i.age + i.mail + " " + i.login + " " + i.password); Console.WriteLine("-------------------------------------------------------------------------------"); } Console.WriteLine(); } static void Main(string[] args)///////////////////////////////////////////////////////////////////////////////// { Greeting(); bool flag = true; while (flag) { Console.WriteLine("Choose 1 for delete"); Console.WriteLine("Choose 2 for update User"); Console.WriteLine("Choose 3 for Output servers info "); Console.WriteLine("Choose 0 for Exit"); int index = Convert.ToInt32(Console.ReadLine()); switch (index) { case 1: { delet(); break; } case 2: { dataLogin(); break; } case 3: { AboutMe(); break; } case 0: { flag = false; break; } } } /* User User1 = new User("Vlad", "Seleznev", "Ukraine", "Male", 17, "removed@mail.ru", "Seleznev12", 12345); User User2 = new User("Ruslan", "Molchanuk", "Ukraine", "Male", 18, "risegaming.com", "rise12", 123456); User User3 = new User("Alexander", "Aprelenko", "Estonia", "Male", 17, "qwerty.com", "apr12", 1234567); User User4 = new User("Andrey", "Tsaryk", "Ukraine", "Male", 21, "sayta.net", "and12", 12345678); User User5 = new User("Patrik", "Buravchuk", "Ukraine", "Male", 16, "negrinafiji.net", "pat12", 123456789); User User6 = new User("Vetrov", "Alexey", "Ukraine", "Male", 17, "vetroveletel.est", "vet12", 12); User User7 = new User("Alexandra", "Suvorova", "Ukraine", "Female", 18, "s.suvorova98", "suv12", 123); User User8 = new User("Piven", "Bogdan", "Ukraine", "Male", 16, "pityxi.com", "bog12", 1234); User[] UsersArray = { User1, User2, User3, User4, User5, User6, User7, User8 }; List<User> UsersList = UsersArray.ToList(); Console.WriteLine("Name|Surname|Country |Sex|Age| |E-mail| |LogIn| |Pasword|"); Console.WriteLine("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); foreach (User i in UsersList) { Console.WriteLine(i.name + " " + i.surname + " " + i.country + " " + i.sex + " " + i.age + " " + i.mail + " " + i.login + " " + i.password); Console.WriteLine("-------------------------------------------------------------------------------"); } Console.WriteLine("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"); */ Console.ReadKey(); } } }
Вот я дебил, не в тот раздел написал. Модераторы, не баньте. Удалите тему, пожалуйста.
Решение задачи: «Не обновляется список пользователей»
textual
Листинг программы
public static void delet() { var UsersList = new List<User>(); //---------------------
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д