.NET 4.x Не выводит найденные элементы в List - C#

Узнай цену своей работы

Формулировка задачи:

Листинг программы
  1. Console.WriteLine(clientList.FindAll(x => x.IsClientByDate(new DateTime(2017, 11, 21))));
Вот эта строчка выводит: А мне надо что бы она выводила три элемента из списка которые подходят по дате в условии поиска... Весь код
Листинг программы
  1. namespace AbstractClient
  2. {
  3. public abstract class Client
  4. {
  5. public abstract void PrintInfo(); //Метод который выводит сведения о эл. класса
  6. public DateTime Date { get; set; }
  7. public bool IsClientByDate(DateTime date)
  8. {
  9. if (Date == date)
  10. return true;
  11. return false;
  12. }
  13. }
  14.  
  15. public class Investor : Client //Класс инвестор
  16. {
  17. public string Surname { get; set; }
  18. public decimal DepositAmount { get; set; }
  19. public double DepositInterest { get; set; }
  20. public Investor(string surname, DateTime depositDate, decimal depositAmount, double depositInteres)
  21. {
  22. Surname = surname;
  23. Date = depositDate;
  24. DepositAmount = depositAmount;
  25. DepositInterest = depositInteres;
  26. }
  27.  
  28. public override void PrintInfo()
  29. {
  30. Console.WriteLine("Фамилия вкладчика: {0}", Surname);
  31. Console.WriteLine("Дата открытия вклада: {0}", Date.ToShortDateString());
  32. Console.WriteLine("Размер вклада: {0}", DepositAmount);
  33. Console.WriteLine("Процент по вкладу: {0}", DepositInterest);
  34. }
  35. }
  36. public class Creditor : Client //Класс кредитор
  37. {
  38. public string Surname { get; set; }
  39. public decimal CreditAmount { get; set; }
  40. public double CreditInterest { get; set; }
  41. public double CreditBalance { get; set; }
  42. public Creditor(string surname, DateTime creditDate, decimal creditAmount, double creditInterest,
  43. double creditBalance)
  44. {
  45. Surname = surname;
  46. Date = creditDate;
  47. CreditAmount = creditAmount;
  48. CreditInterest = creditInterest;
  49. CreditBalance = creditBalance;
  50. }
  51. public override void PrintInfo()
  52. {
  53. Console.WriteLine("Фамилия кредитора: {0}", Surname);
  54. Console.WriteLine("Дата выдачи кредита: {0}", Date.ToShortDateString());
  55. Console.WriteLine("Размер кредита: {0}", CreditAmount);
  56. Console.WriteLine("Процент по кредиту: {0}", CreditInterest);
  57. Console.WriteLine("Остаток долга: {0}", CreditBalance);
  58. }
  59.  
  60. }
  61. public class Organization : Client //Класс организация
  62. {
  63. public string Name { get; set; }
  64. public int AccountNumber { get; set; }
  65. public decimal AccountAmount { get; set; }
  66. public Organization(string name, DateTime accountDate, int accountNumber, decimal accountAmount)
  67. {
  68. Name = name;
  69. Date = accountDate;
  70. AccountNumber = accountNumber;
  71. AccountAmount = accountAmount;
  72. }
  73. public override void PrintInfo()
  74. {
  75. Console.WriteLine("Название организации: {0}", Name);
  76. Console.WriteLine("Дата открытия счета: {0}", Date.ToShortDateString());
  77. Console.WriteLine("Номер счета: {0}", AccountNumber);
  78. Console.WriteLine("Сумма на счету: {0}", AccountAmount);
  79. }
  80.  
  81. }
  82. class Program
  83. {
  84. static void Main(string[] args)
  85. {
  86. List<Client> clientList = new List<Client>() //Объявление списка и добавление в него 3х элементов
  87. { new Investor ("alex", new DateTime (2017,11,21),21,12),
  88. new Creditor ("dan", new DateTime (2017,11,21),21,12,43),
  89. new Organization ("corp", new DateTime (2017,11,21),21,12)};
  90. Link:
  91. Console.WriteLine("1. Отобразить список.");
  92. Console.WriteLine("2. Добавить.");
  93. Console.WriteLine("3. Удалить.");
  94. Console.WriteLine("4. Найти по дате.");
  95. try
  96. {
  97. string s = Console.ReadLine();
  98. if (s == "1") //Отображение списка
  99. {
  100. Console.Clear();
  101. foreach (Client client in clientList)
  102. {
  103. client.PrintInfo();
  104. Console.WriteLine();
  105. }
  106. }
  107. else if (s == "2") //Добавление нового элемента в список
  108. {
  109. Console.Clear();
  110. Console.WriteLine("1. Добавить инвестора.");
  111. Console.WriteLine("2. Добавить кредитора.");
  112. Console.WriteLine("3. Добавить организацию.");
  113. string s2 = Console.ReadLine();
  114. Console.Clear();
  115. if (s2 == "1")
  116. {
  117. Console.WriteLine("Введите имя, размер вклада, процент по вкладу. После ввода каждого пораметра нажмите 'enter'");
  118. clientList.Add(new Investor(Console.ReadLine(), DateTime.Now, Convert.ToDecimal(Console.ReadLine()), Convert.ToDouble(Console.ReadLine())));
  119. }
  120. else if (s2 == "2")
  121. {
  122. Console.WriteLine("Введите имя, размер кредита, процент по кредиту, остаток долга. После ввода каждого пораметра нажмите 'enter'");
  123. clientList.Add(new Creditor(Console.ReadLine(), DateTime.Now, Convert.ToDecimal(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()), Convert.ToDouble(Console.ReadLine())));
  124. }
  125. else if (s2 == "3")
  126. {
  127. Console.WriteLine("Введите название организации, номер счета, сумма на счету. После ввода каждого пораметра нажмите 'enter'");
  128. clientList.Add(new Organization(Console.ReadLine(), DateTime.Now, Convert.ToInt16(Console.ReadLine()), Convert.ToDecimal(Console.ReadLine())));
  129. }
  130. }
  131. else if (s == "3") //Удаление элемента из списка
  132. {
  133. foreach (Client client in clientList)
  134. {
  135. client.PrintInfo();
  136. Console.WriteLine();
  137. }
  138. Console.WriteLine("Введите номер записи которую необходимо удалить:");
  139. clientList.RemoveAt(Convert.ToInt16(Console.ReadLine()) - 1);
  140. Console.Clear();
  141. foreach (Client client in clientList)
  142. {
  143. client.PrintInfo();
  144. Console.WriteLine();
  145. }
  146. }
  147. else if (s == "4") //Поиск по дате
  148. Console.WriteLine(clientList.FindAll(x => x.IsClientByDate(new DateTime(2017, 11, 21))));
  149. }
  150. catch (FormatException)
  151. { Console.WriteLine("Несоответствие формата"); }
  152. Console.ReadLine();
  153. Console.Clear();
  154. goto Link;
  155. }
  156. }
  157. }

Решение задачи: «.NET 4.x Не выводит найденные элементы в List»

textual
Листинг программы
  1. var found = clientList.FindAll(x => x.IsClientByDate(new DateTime(2017, 11, 21)));
  2. foreach (var c in found)
  3. {
  4.     c.PrintInfo();
  5. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4.25 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы