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#

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

Jagged Arrays What is the problem in this coding?

I just copied the coding from the Jagged Arrays video. https://teamtreehouse.com/library/jagged-arrays I need to make it work in order to finish the next coding changlle. In this video we just quitly inducted for loop and using C# object without explaining it. I feel the Treehouse instructor should spend more time to explain it more detailly.

Personal Comment There should be a comment below each video in order to listen what should the video need to be improved. Such as in the python object video , Mr Love doesn't really explain why and how main works ,and he just keeps using it for next and next video. Some peopel said he is the fan of Mr Love ,and he said i should spend more time to google search it. However, i think they can just spend extra few mins to explain what they skipped ,and that could be fine.

I want the following code creating 100 rows with 10 cells in each.

class Cell;
    {
            public string Contents { get; set; }
        }
    Cell[][] sheet = new Cell[100][];
    sheet[9] = new Cell[10];
    for(int rowIndex = 0; rowIndex < sheet.Length; rowIndex++)
    {
        sheet[rowIndex] = new Cell[10]; //creata row of 10 cells
        for(int colIndex = 0; colIndex < sheet[rowIndex].Length; colIndex++)
        {
            sheet[rowIndex][colIndex] = new Cell();

        }
    }
}
        //mcs Cell.cs && mono Cell.exe

1 Answer

Steven Parker
Steven Parker
231,210 Points

:point_right: It looks like you're trying to compile code intended for the REPL.

The REPL ("csharp") lets you experiment with things that would not be proper for a compiled program. For example, in a program you would not just write a loop without enclosing it in a method.

You could turn this code into a compiled program if you want, by wrapping everything not part of the Cell class in another class and a static Main method.

Also, you have a stray semicolon on the top line after "Class Cell".