NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP 
Author Message
 NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

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;

    }

Quote:
}

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: __________________________________________________________________



Tue, 23 Nov 2004 20:03:27 GMT  
 NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

Quote:
> 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;
>     }
> }

For starters, why are you using char to store numbers? int ( or short when
you just want to use 2 bytes ) not better?
Secondly, you code is correct. It runs just fine on my computer, so I
presume the problem lies somewhere else. The fact that you report a
NullReferenceExption might give some clue, maybe you supply the wrong array
to the method?
What about:

// some declaration somewhere
const int gridLength = 25;
public static short [,] grid = new short[ gridLength, gridLength ];

// some method somewhere to initalize your array
public Test( short[,] grid )
{
    for( int i = 0; i < grid.GetUpperBound( 0 ); i++ )
        for( int j = 0; j < grid.GetUpperBound( 1 ); j++ )
            grid[ i, j ]= 1600;

Quote:
}

this way you don't have to care about the dimensions of your array.


Tue, 23 Nov 2004 22:24:01 GMT  
 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:

__________________________________________________________________

- Show quoted text -



Tue, 23 Nov 2004 22:27:59 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

2. Please help!!!!Please help!!!!Please help!!!!

3. help: Guru needed please please please

4. HELP Please Please (malloc on an array)

5. need help please please setting registry value

6. need help with arrays please

7. Need Help with array...Please Advice

8. Help Please-need algorithm for getting 9 point average in 2d array

9. PLEASE PLEASE HELP HELP...question on interleaving C functions

10. Help C newbie need help please

11. Help C newbie need help please

12. I really need some help with C graphics PLEASE HELP

 

 
Powered by phpBB® Forum Software