I have an array that contains two values that is supposed to represent a point on a x and y diagram, the first value being the x value of the point and the second value being the y value of the point.
I then want to store all of the points contained in an area of a square in a list.
I put a break point where the array gets added to the list and it seems to be adding the correct values to the list, namely: 100 10 100 9 etc.
But when I run the program it prints 105 for array[0] and 5 for array[1] for each array in the list.
class Program
{
static void Main(string[] args)
{
List<int[]> points = new List<int[]>();
int[] point = new int[2];
string topLeftCornerX = "100";
string topLeftCornerY = "10";
for (int i = int.Parse(topLeftCornerX); i < int.Parse(topLeftCornerX) +6; i++)
{
point[0] = i;
for (int j = int.Parse(topLeftCornerY); j > int.Parse(topLeftCornerY) -6; j--)
{
point[1] = j;
points.Add(point);
}
}
foreach (int[] item in points)
{
Console.WriteLine(item[0]);
Console.WriteLine(item[1]);
}
Console.ReadLine();
}
}
Is there a problem with the way I'm adding the array to the list or just the way I'm printing the values?