In: Computer Science
// c# printing to cmd line
// 1 im trying to pring thing1 thing1 is a simple list with 2 elements [10,2]
// then i try to create a grid of zeroes
// and finally change 1 element of the grid to a 1. but none of this seems to work
using System;
namespace cmd_line_game_2
{
class Program
{
static void Main(string[] args)
{
int number_of_lines = 29;
int number_of_chars = 11;
int[] thing1 = new int[2] { 10, 2};
//int [] thing1 = { 10, 2 };
int [,] grid1 = new int[number_of_chars, number_of_lines];
Console.WriteLine("thing below");
Console.WriteLine(thing1); // this should print [10,2] but it
doesnt
Console.ReadKey();
while (1 < 2)
{
for (int y = 0; y < number_of_lines; y++)
{
for (int x = 0; x < number_of_chars; x++)
{
grid1[x, y] = 0; // for each x and y fill up the grid with
zeroes
}
}
grid1[thing1[0], thing1[1]] = 1; // then change this 1 co-ordinate
of the grid to a 1
Console.WriteLine("grid below");
Console.WriteLine(grid1);
Console.ReadKey();
}
}
}
}
You can't simply pass an array as a parameter to console.writeline .
Changing this to :-
foreach (int element in thing1) Console.WriteLine(element);
would do the job.
Input and output are as below :-
Please up-vote the answer if you liked it. Feel free to ask for any explanation in comments.