Ошибка process is terminated due to stackoverflowexception - C#

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

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

Подскажыте что сделать что бы код заработал
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleApplication17
  7. {
  8. namespace Finance
  9. {
  10. class Bank
  11. {
  12. People.Client[] clinets;
  13. public Bank()
  14. {
  15. clinets = new People.Client[0];
  16. }
  17. public void add_account()
  18. {
  19. People.Client[] c;
  20. c = new People.Client[clinets.Length+1];
  21. Array.Resize(ref clinets, clinets.Length + 1);
  22. clinets[clinets.Length - 1] = new People.Client();
  23. clinets[clinets.Length - 1].info();
  24. }
  25. public void print_balance(){
  26. Console.WriteLine("");
  27. }
  28. public People.Client open_account(Bank b, string str) {
  29. for (int i = 0; i < clinets.Length; i++)
  30. {
  31. if (clinets[i].find_card(str) == true) return b.clinets[i];
  32. }
  33. return null;
  34. }
  35. public void set_ac(Bank b, string str) {
  36. open_account(b, str).set_info();
  37. }
  38. }
  39. }
  40. namespace People
  41. {
  42. class Client
  43. {
  44. Login.Account accounts;
  45. string name;
  46. string surname;
  47. string city;
  48. public Client(){
  49. accounts = new Login.Account();
  50. name = null;
  51. surname = null;
  52. city = null;
  53. }
  54. public bool find_card(string str)
  55. {
  56. for(int i = 0; i<accounts.Length; i++)
  57. if (accounts.Number_Card == str) return true;
  58. return false;
  59. }
  60. public void print()
  61. {
  62. Console.WriteLine("name: " + name);
  63. Console.WriteLine("surname: " + surname);
  64. Console.WriteLine("city: " + city);
  65. }
  66. public void info() {
  67. Console.WriteLine("Card: " + accounts.Number_Card);
  68. Console.WriteLine("Password: " + accounts.Password);
  69. Console.WriteLine("Balance: " + accounts.Balance);
  70. }
  71. public void balance()
  72. {
  73. Console.WriteLine("Balance: " + accounts.Balance);
  74. }
  75. public void set_info() {
  76. Console.Write("name: ");
  77. name = Console.ReadLine();
  78. Console.Write("surname: ");
  79. surname = Console.ReadLine();
  80. Console.Write("city: ");
  81. city = Console.ReadLine();
  82. }
  83. public void set_balance() {
  84. accounts.Balance += Convert.ToInt32(Console.ReadLine());
  85. }
  86. public void credit_balance()
  87. {
  88. accounts.Balance -= Convert.ToInt32(Console.ReadLine());
  89. }
  90. }
  91. }
  92. namespace Login
  93. {
  94. class Account
  95. {
  96. string number_card;
  97. string password;
  98. int balance;
  99. Random rand;
  100. public Account()
  101. {
  102. rand = new Random();
  103. for (int i = 0; i < 16; i++)
  104. {
  105. number_card += Convert.ToString(rand.Next(0, 9));
  106. if (i == 3 || i == 7 || i == 11) number_card += " ";
  107. }
  108. for (int i = 0; i < 8; i++)
  109. {
  110. password += Convert.ToString(Convert.ToChar(rand.Next(48, 122)));
  111. }
  112. balance = 0;
  113. }
  114. public string Number_Card
  115. {
  116. get
  117. {
  118. return number_card;
  119. }
  120. set
  121. {
  122. number_card = value;
  123. }
  124. }
  125. public string Password
  126. {
  127. get
  128. {
  129. return password;
  130. }
  131. set
  132. {
  133. password = value;
  134. }
  135. }
  136. public int Balance
  137. {
  138. get
  139. {
  140. return balance;
  141. }
  142. set
  143. {
  144. Balance = value;
  145. }
  146. }
  147. }
  148. }
  149. class Program
  150. {
  151. static void Main(string[] args)
  152. {
  153. Finance.Bank b1 = new Finance.Bank();
  154. int change = 0;
  155. int change2 = 0;
  156. string str;
  157. str = null;
  158. while (change != 3)
  159. {
  160. Console.WriteLine("1 - Add account");
  161. Console.WriteLine("2 - open account");
  162. Console.WriteLine("3 - exit");
  163. change = Convert.ToInt32(Console.ReadLine());
  164. if (change == 1)
  165. {
  166. b1.add_account();
  167. continue;
  168. }
  169. if (change == 2) {
  170. Console.Write("Number card: ");
  171. str = Console.ReadLine();
  172. if (b1.open_account(b1, str) == null)
  173. {
  174. Console.WriteLine("Not card");
  175. continue;
  176. }
  177. else b1.set_ac(b1, str);
  178. }
  179. if (change == 3) break;
  180. while (change2 != 4) {
  181. Console.WriteLine("1 - Print balance");
  182. Console.WriteLine("2 - Add balance");
  183. Console.WriteLine("3 - Credit balance");
  184. Console.WriteLine("4 - Exit to menu");
  185. change2 = Convert.ToInt32(Console.ReadLine());
  186. switch (change2) {
  187. case 1:
  188. b1.open_account(b1, str).balance();
  189. break;
  190. case 2:
  191. b1.open_account(b1, str).set_balance();
  192. break;
  193. case 3:
  194. b1.open_account(b1, str).credit_balance();
  195. break;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
в методах
Листинг программы
  1. b1.open_account(b1, str).set_balance();
и
Листинг программы
  1. b1.open_account(b1, str).credit_balance();

Решение задачи: «Ошибка process is terminated due to stackoverflowexception»

textual
Листинг программы
  1. public int Balance { get; set; }

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


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

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

11   голосов , оценка 4 из 5

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

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

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