0

Не получается вывести List в консоль, не ругается, просто не выводит.

Вот коды:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gallows
{
    class Program
    {
        static void Main(string[] args)
        {
            char letter; // буква, вводимая игроком с консоли

            string word = Console.ReadLine(); // игровое слово 

            List<char> wordList = word.ToList(); // массив букв из игрового слова

            List<char> consList = new List<char>(wordList.Count); // слово в консоли

            int errors = 0; // количство ошибок

            int gameResult = 0; // статус игры(0 - игра идет, -1 - проигрыш, 1 - победа)

            Methods method = new Methods(); // экземпляр класс для использования методов

            for(int i = 0; i < consList.Count; i++) // скрываем буквы в консоли
            {
                consList[i] = '_';
            }

            while(gameResult == 0)
            {
                method.Info(consList, errors);

                letter = Console.ReadKey().KeyChar;

                gameResult = method.CheckErrors(errors);
            }
            Console.ReadKey();
        }
    }
}

И второй класс:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gallows
{
    class Methods
    {
        public int CheckErrors(int errors)
        {
            if(errors == 7)
            {
                return -1;
            }
            else
            {
                return 0;
            }
        }

        public void Info(List<char> consList, int errors)
        {
            for(int i = 0; i < consList.Count; i++)
            {
                Console.WriteLine(consList[i]);
            }

            Console.WriteLine($"Количество ошибок: {errors}");
        }
    }
}

Помогите решить эту проблему.

2
  • 4
    А почему вы не пользуетесь отладчиком?
    – VladD
    16 сен 2017 в 21:43
  • Поддержу комментарий выше, а так List<char> consList = new List<char>(wordList.Count);.
    – EvgeniyZ
    16 сен 2017 в 21:55

1 ответ 1

1

Этот кусок кода не работает.

List<char> consList = new List<char>(wordList.Count); // слово в консоли

поменяйте на

List<char> wordList = word.ToList(); // массив букв из игрового слова

List<char> consList = new List<char>(); // слово в консоли

for (int i = 0; i < wordList.Count; i++) // скрываем буквы в консоли
{
    consList.Add('_');
}

и можете дальше править ошибки в логике игры

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.