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 trialyujia liu
14,964 PointsI got error "Index was outside the bounds of the array." I cannot figure out what wrong with my code
There are 4 rows and 4 columns, so I think index is fine
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static int[,] BuildMultiplicationTable(int maxFactor)
{
int[,] sheet = new int[maxFactor + 1, maxFactor + 1];
for(int i=0; i< sheet.GetLength(0); i++)
{
for(int j=0;i< sheet.GetLength(1); j++)
{
sheet[i,j] = i * j;
}
}
return sheet;
}
}
}
1 Answer
Steven Parker
231,248 PointsIt looks like you just have a typo.
In your second loop, the index variable you initialize and increment is "j", but the one in the condition is "i".