[Mono-list] Some C# problems

Piers Haken piersh@friskit.com
Mon, 5 Aug 2002 16:34:51 -0700


Works ok for me on .net.

I seem to remember someone mentioning a bug in rectangular arrays a
while back, maybe it's not fixed yet?

piers.

-----Original Message-----
From: Kenneth Christiaansen [mailto:kenneth@gnu.org]
Sent: Monday, August 05, 2002 3:48 PM
To: mono-list@ximian.com
Subject: [Mono-list] Some C# problems


He everyone,

I am having some problems with the attached code. This is the first I
play
with C# so it might include sillynesses. It compiles fine, but I get the
following failures while running the code:

** (process:31789): WARNING **: unhandled exception
System.NullReferenceException: "A null value was found where an object
instance was required"
in (unmanaged) (managed to native wrapper) System.Array:GetLength (int)
in <0x00004> (managed to native wrapper) System.Array:GetLength (int)
in <0x00079> .Board:.ctor (int)
in <0x0005c> .TicTacToe:Main ()

So if anyone can give me a hint on what I am doing wrong, or tell me
this is
a bug, then please feel free doing so.

Cheers, Kenneth


using System;

class TicTacToe {

 class Board {
  enum Block {
   Circle,
   Cross,
   None,
  };

  private Block [,] board;

  public Board (int size)
  {
   board = new Block [size, size];

   for (int i = 0; i < board.GetLength (0); i++) {
    for (int j = 0; j < board.GetLength (1); j++) {
     board [i, j] = Block.None;
    }
   }
  }

  public void DrawBoard ()
  {
   for (int i = 0; i < board.GetLength (0); i++) {
    for (int j = 0; j < board.GetLength (1); j++) {
     switch (board [i, j])
     {
     case Block.None:
      Console.Write (".");
      break;
     case Block.Cross:
      Console.Write ("X");
      break;
     case Block.Circle:
      Console.Write ("O");
      break;
     }
    }
    Console.WriteLine ("");
   }
  }
 }

 static public void Main ()
 {
  Console.WriteLine ("Welcome to Tic Tac Toe");
  Board board = new Board (10);
  board.DrawBoard ();
 }
}



_______________________________________________
Mono-list maillist  -  Mono-list@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list