
NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP
This pretty much worked for me. Post some more of your code if you haven't
figured it out yet... But here's something that works for me:
using System;
class Driver
{
private const int gridLength = 5;
public static char [,] grid= new char[gridLength,gridLength];
static void Main()
{
for(int i=0;i<gridLength;i++){
for(int j=0;j<gridLength;j++){
grid[i,j]=(char)88; // (char)1600; would be okay here as
well I guess
}
}
for(int i=0;i<gridLength;i++){
for(int j=0;j<gridLength;j++){
Console.Write(grid[i,j]);
}
Console.WriteLine();
}
}
Quote:
}
--
Gus Perez
C# Compiler Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Quote:
> HI every one i am new to C# and i am trying make a game in C#
> i wanne make it work in console then make a window application version out
> of it
> you know with all the gui and stuff
> ok i wanne make 2D array and the loop trhough it and print them all
elements
> out
> for example in java it would be something like this
> static final char [][] grid= new char[gridLength][gridLength];
> for(i=0;i<grid.length;i++){
> for(j=0;j<grid[i].length;j++){
> grid[i][j]=(char)1600;
> }
> }
> i am having trouble donig the same thing in C#
> my code
> public static char [,] grid= new char[gridLength,gridLength];
> for(i=0;i<gridLength;i++){
> for(j=0;j<gridLength;j++){
> grid[i,j]=(char)1600;
> }
> }
> BUt this is not working, i get either indexout of bouse exception or
> nullpointer exception
> how can i fix it thanx
> __________________________________________________________________ amir
> ICQ#: 103822985 Current ICQ status: + More ways to contact me i See more
> about me:
__________________________________________________________________