How do I create a terminable while loop in console application?

前端 未结 7 1866
情话喂你
情话喂你 2021-01-16 04:41

I am currently looking for a solution for this c# console application function

I tried searching for a method for creating a while loop that can terminate for the co

7条回答
  •  温柔的废话
    2021-01-16 05:19

    Here is code based on the post you deleted :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                BattleGrid grid = new BattleGrid();
                grid.PrintGrid();
                Console.ReadLine();
            }
        }
        public class BattleGrid
        {
            public List> grid = new List>();
    
            public BattleGrid()
            {
                for (int row = 0; row < 4; row++)
                {
                    List newRow = new List();
                    grid.Add(newRow);
                    for (int col = 0; col < 4; col++)
                    {
                        BattleGridCell newCell = new BattleGridCell();
                        newRow.Add(newCell);
                        newCell.rowLetter = ((char)((int)'A' + row)).ToString();
                        newCell.colnumber = col.ToString();
                    }
                }
            }
            public void PrintGrid()
            {
                foreach (List row in grid)
                {
                    Console.WriteLine("|" + string.Join("|", row.Select(x => "X" + x.rowLetter + x.colnumber))); 
                }
            }
        }
    
        public class BattleGridCell
        {
            public string rowLetter { get; set; }
            public string colnumber { get; set; }
        }
    }
    

提交回复
热议问题