Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Ruth O'Kelly
Ruth O'Kelly
4,944 Points

My console prints out Collections.Cell 100 times instead of each individual Cell object (when using Visual Studio).

In my below code, the Visual Studio console prints 'Collections.Cell' 100 times instead of what the teacher's REPL produces. Can anyone see a problem with my code?

static void Main(string[] args) { Cell[][] sheet = new Cell[100][];

        for (int rowIndex = 0; rowIndex < sheet.Length; rowIndex++)
        {
            sheet[rowIndex] = new Cell[10];

            for (int colIndex = 0; colIndex < sheet[rowIndex].Length; colIndex++)
            {
                sheet[rowIndex][colIndex] = new Cell();
            }
        }

        foreach (Cell[] row in sheet)
        {
            foreach (Cell cell in row)
            {
                Console.WriteLine(cell);
            }
        }          
        Console.ReadLine();
    }

1 Answer

Steven Parker
Steven Parker
231,110 Points

It's not clear that anything is wrong. I don't see where you defined "Cell" in this code, but it looks like a definition from the namespace "Collections" is being included. And in that case, displaying "Collections.Cell" would be correct since that would be the fully-qualified name of that object's class.