示例#1
0
        static Account GetAccount(List <Account> list, Account currAccount)
        {
            Account act         = null;
            int     optionCount = list.Count;

            Console.WriteLine("Count: =" + optionCount);
            int count = 1;
            int option;
            int index = 0;

            do
            {
                Console.WriteLine("\t*-------------Choose Transfer Account-------------*");
                Console.WriteLine("Choose one of the following Accounts to transfer funds too (Enter 0 to go back):");
                foreach (var acct in list)
                {
                    if (!currAccount.Equals(acct))
                    {
                        Console.WriteLine($"{count}) {acct.ToString()}");
                        count++;
                    }
                    else
                    {
                        Console.WriteLine($"**[{count}) {acct.ToString()}]**");
                        index = count;
                        count++;
                    }
                }
                Console.Write("Choose Account: ");
                string str = Console.ReadLine();
                count = 1;
                if (!int.TryParse(str, out option))
                {
                    Console.WriteLine($"Error: [{str}] is not a option");
                }
                else if (option == 0)
                {
                    break; //brake out of loop to go back to Action Menu
                }
                else if (option < 1 || option > optionCount)
                {
                    Console.WriteLine($"Error: {option} is not an option");
                }
                else if (option == index)
                {
                    Console.WriteLine($"Error: Cannot transfer to same account, choose a different one");
                }
                else
                {
                    act = list[option - 1];
                    //Console.WriteLine("Option" + (option-1));
                    break;
                }
            } while (true);
            return(act);
        }