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

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

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

Подскажыте что сделать что бы код заработал
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication17
{
 
    namespace Finance
    {
        class Bank
        {
            People.Client[] clinets;
            public Bank()
            {
                clinets = new People.Client[0];
            }
            public void add_account()
            {
                People.Client[] c;
                c = new People.Client[clinets.Length+1];
                Array.Resize(ref clinets, clinets.Length + 1);
                clinets[clinets.Length - 1] = new People.Client();
                clinets[clinets.Length - 1].info();
                                
            }
            public void print_balance(){
                Console.WriteLine("");
            }
            public People.Client open_account(Bank b, string str) {
                for (int i = 0; i < clinets.Length; i++)
                {
                    if (clinets[i].find_card(str) == true) return b.clinets[i];
                  }
                return null;
               }
            public void set_ac(Bank b, string str) {
                open_account(b, str).set_info();
            }
         }
    }
        namespace People
        {
            class Client
            {
                Login.Account accounts;
                string name;
                string surname;
                string city;
                public Client(){
                accounts = new Login.Account();
                name = null;
                surname = null;
                city = null;
                }
                public bool find_card(string str)
                {
                    for(int i = 0; i<accounts.Length; i++)
                    if (accounts.Number_Card == str) return true;
                    return false;
                }
                public void print()
                {
                    Console.WriteLine("name: " + name);
                    Console.WriteLine("surname: " + surname);
                    Console.WriteLine("city: " + city);
                }
                public void info() {
                    Console.WriteLine("Card: " + accounts.Number_Card);
                    Console.WriteLine("Password: " + accounts.Password);
                    Console.WriteLine("Balance: " + accounts.Balance);
                }
                public void balance()
                {
                    Console.WriteLine("Balance: " + accounts.Balance);
                }
                public void set_info() {
                    Console.Write("name: ");
                    name = Console.ReadLine();
                    Console.Write("surname: ");
                    surname = Console.ReadLine();
                    Console.Write("city: ");
                    city = Console.ReadLine();
                }
                public void set_balance() {
                    accounts.Balance += Convert.ToInt32(Console.ReadLine());
                }
                public void credit_balance()
                {
                    accounts.Balance -= Convert.ToInt32(Console.ReadLine());
                }
            }
        }
        namespace Login
        {
            class Account
            {
                string number_card;
                string password;
                int balance;
                Random rand;
                public Account()
                {
                    rand = new Random();
                    for (int i = 0; i < 16; i++)
                    {
                       
                        number_card += Convert.ToString(rand.Next(0, 9));
                        if (i == 3 || i == 7 || i == 11) number_card += " ";
 
                    }
                    for (int i = 0; i < 8; i++)
                    {
                        password += Convert.ToString(Convert.ToChar(rand.Next(48, 122)));
                    }
                    balance = 0;
                }
                public string Number_Card
                {
                    get
                    {
                        return number_card;
                    }
                    set
                    {
                        number_card = value;
                    }
                }
                public string Password
                {
                    get
                    {
                        return password;
                    }
                    set
                    {
                        password = value;
                    }
                }
                public int Balance
                {
                    get
                    {
                        return balance;
                    }
                    set
                    {
                        Balance = value;
                    }
                }
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                Finance.Bank b1 = new Finance.Bank();
                int change = 0;
                int change2 = 0;
                string str;
                str = null;
                while (change != 3)
                {
                Console.WriteLine("1 - Add account");
                Console.WriteLine("2 - open account");
                Console.WriteLine("3 - exit");
                change = Convert.ToInt32(Console.ReadLine());
                if (change == 1)
                {
                    b1.add_account();
                    continue;
                }
                if (change == 2) {
                Console.Write("Number card: ");
                str = Console.ReadLine();
                if (b1.open_account(b1, str) == null)
                {
                    Console.WriteLine("Not card");
                    continue;
                }
                else b1.set_ac(b1, str);
                }
                if (change == 3) break;
                while (change2 != 4) {
                    Console.WriteLine("1 - Print balance");
                    Console.WriteLine("2 - Add balance");
                    Console.WriteLine("3 - Credit balance");
                    Console.WriteLine("4 - Exit to menu");
                    change2 = Convert.ToInt32(Console.ReadLine());
                    switch (change2) { 
                        case 1:
                          b1.open_account(b1, str).balance();
                          break;
                        case 2:
                          b1.open_account(b1, str).set_balance();
                          break;
                        case 3:
                          b1.open_account(b1, str).credit_balance();
                          break;
                   }
                
                }
                 }
                
            }
        }
    }
в методах
b1.open_account(b1, str).set_balance();
и
b1.open_account(b1, str).credit_balance();

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

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

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


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

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

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