-1

So I'm currently working on a project for my C# class where we have to recreate Minesweeper using the Console. I'm fairly new to C# but have worked with other code languages before so I've been able to sort out most problems. The newest one i'm having is I've made two functions (one that creates cells and stores them in a list, the other to print them in a grid pattern), one of them works (GenerateCells) but the other doesn't output anything when ran.

    //PrintGrid Function
    public static void PrintGrid(int gsize, List<Cell> cells)
    {
        for (int x = 0; x > gsize; x++)
        {
    //testing output
            Console.WriteLine(cells[0].Name);
        }
    }
class Program
    {
        static void Main(string[] args) {
            //Set Default Grid Size
            int gsize = 6;
            //Create List of Cells
            var cells = new List<Cell>
                {
                //Generate "Ghost Cell" preventing exception
                new Cell { Name = "Ghost Cell", XCord = 0, YCord = 0 }
                };
            //Generate Cells for grid
            Cell.GenerateCells(gsize, cells);
            //Print Cells in grid
            Cell.PrintGrid(gsize, cells);
        }
    }

I'm not sure what I'm doing wrong since there are no errors that pop up. All I can figure is I've either called it wrong or set up the method wrong, but I can't figure it out. Any and all help is appreciated.

1 Answers1

0

You just have '>' instead of '<'. So this is what it should look like:

public static void PrintGrid(int gsize, List<Cell> cells)
{
    for (int x = 0; x < gsize; x++)
    {
        //testing output
        //This one has to have the index instead of 0. 
        Console.WriteLine(cells[x].Name);
    }
}