.NET 4.x Не выводит найденные элементы в List - C#
Формулировка задачи:
Листинг программы
- Console.WriteLine(clientList.FindAll(x => x.IsClientByDate(new DateTime(2017, 11, 21))));
Листинг программы
- namespace AbstractClient
- {
- public abstract class Client
- {
- public abstract void PrintInfo(); //Метод который выводит сведения о эл. класса
- public DateTime Date { get; set; }
- public bool IsClientByDate(DateTime date)
- {
- if (Date == date)
- return true;
- return false;
- }
- }
- public class Investor : Client //Класс инвестор
- {
- public string Surname { get; set; }
- public decimal DepositAmount { get; set; }
- public double DepositInterest { get; set; }
- public Investor(string surname, DateTime depositDate, decimal depositAmount, double depositInteres)
- {
- Surname = surname;
- Date = depositDate;
- DepositAmount = depositAmount;
- DepositInterest = depositInteres;
- }
- public override void PrintInfo()
- {
- Console.WriteLine("Фамилия вкладчика: {0}", Surname);
- Console.WriteLine("Дата открытия вклада: {0}", Date.ToShortDateString());
- Console.WriteLine("Размер вклада: {0}", DepositAmount);
- Console.WriteLine("Процент по вкладу: {0}", DepositInterest);
- }
- }
- public class Creditor : Client //Класс кредитор
- {
- public string Surname { get; set; }
- public decimal CreditAmount { get; set; }
- public double CreditInterest { get; set; }
- public double CreditBalance { get; set; }
- public Creditor(string surname, DateTime creditDate, decimal creditAmount, double creditInterest,
- double creditBalance)
- {
- Surname = surname;
- Date = creditDate;
- CreditAmount = creditAmount;
- CreditInterest = creditInterest;
- CreditBalance = creditBalance;
- }
- public override void PrintInfo()
- {
- Console.WriteLine("Фамилия кредитора: {0}", Surname);
- Console.WriteLine("Дата выдачи кредита: {0}", Date.ToShortDateString());
- Console.WriteLine("Размер кредита: {0}", CreditAmount);
- Console.WriteLine("Процент по кредиту: {0}", CreditInterest);
- Console.WriteLine("Остаток долга: {0}", CreditBalance);
- }
- }
- public class Organization : Client //Класс организация
- {
- public string Name { get; set; }
- public int AccountNumber { get; set; }
- public decimal AccountAmount { get; set; }
- public Organization(string name, DateTime accountDate, int accountNumber, decimal accountAmount)
- {
- Name = name;
- Date = accountDate;
- AccountNumber = accountNumber;
- AccountAmount = accountAmount;
- }
- public override void PrintInfo()
- {
- Console.WriteLine("Название организации: {0}", Name);
- Console.WriteLine("Дата открытия счета: {0}", Date.ToShortDateString());
- Console.WriteLine("Номер счета: {0}", AccountNumber);
- Console.WriteLine("Сумма на счету: {0}", AccountAmount);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Client> clientList = new List<Client>() //Объявление списка и добавление в него 3х элементов
- { new Investor ("alex", new DateTime (2017,11,21),21,12),
- new Creditor ("dan", new DateTime (2017,11,21),21,12,43),
- new Organization ("corp", new DateTime (2017,11,21),21,12)};
- Link:
- Console.WriteLine("1. Отобразить список.");
- Console.WriteLine("2. Добавить.");
- Console.WriteLine("3. Удалить.");
- Console.WriteLine("4. Найти по дате.");
- try
- {
- string s = Console.ReadLine();
- if (s == "1") //Отображение списка
- {
- Console.Clear();
- foreach (Client client in clientList)
- {
- client.PrintInfo();
- Console.WriteLine();
- }
- }
- else if (s == "2") //Добавление нового элемента в список
- {
- Console.Clear();
- Console.WriteLine("1. Добавить инвестора.");
- Console.WriteLine("2. Добавить кредитора.");
- Console.WriteLine("3. Добавить организацию.");
- string s2 = Console.ReadLine();
- Console.Clear();
- if (s2 == "1")
- {
- Console.WriteLine("Введите имя, размер вклада, процент по вкладу. После ввода каждого пораметра нажмите 'enter'");
- clientList.Add(new Investor(Console.ReadLine(), DateTime.Now, Convert.ToDecimal(Console.ReadLine()), Convert.ToDouble(Console.ReadLine())));
- }
- else if (s2 == "2")
- {
- Console.WriteLine("Введите имя, размер кредита, процент по кредиту, остаток долга. После ввода каждого пораметра нажмите 'enter'");
- clientList.Add(new Creditor(Console.ReadLine(), DateTime.Now, Convert.ToDecimal(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()), Convert.ToDouble(Console.ReadLine())));
- }
- else if (s2 == "3")
- {
- Console.WriteLine("Введите название организации, номер счета, сумма на счету. После ввода каждого пораметра нажмите 'enter'");
- clientList.Add(new Organization(Console.ReadLine(), DateTime.Now, Convert.ToInt16(Console.ReadLine()), Convert.ToDecimal(Console.ReadLine())));
- }
- }
- else if (s == "3") //Удаление элемента из списка
- {
- foreach (Client client in clientList)
- {
- client.PrintInfo();
- Console.WriteLine();
- }
- Console.WriteLine("Введите номер записи которую необходимо удалить:");
- clientList.RemoveAt(Convert.ToInt16(Console.ReadLine()) - 1);
- Console.Clear();
- foreach (Client client in clientList)
- {
- client.PrintInfo();
- Console.WriteLine();
- }
- }
- else if (s == "4") //Поиск по дате
- Console.WriteLine(clientList.FindAll(x => x.IsClientByDate(new DateTime(2017, 11, 21))));
- }
- catch (FormatException)
- { Console.WriteLine("Несоответствие формата"); }
- Console.ReadLine();
- Console.Clear();
- goto Link;
- }
- }
- }
Решение задачи: «.NET 4.x Не выводит найденные элементы в List»
textual
Листинг программы
- var found = clientList.FindAll(x => x.IsClientByDate(new DateTime(2017, 11, 21)));
- foreach (var c in found)
- {
- c.PrintInfo();
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д