[Mono-list] Matrix of Objects

Phillip Neumann bob@sofsis.cl
Wed, 02 Mar 2005 22:30:13 +0000


This is a multi-part message in MIME format.
--------------070107050805060409040400
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello...

I wonder how to work with arrays of objects.

i have this:


<this>
public class Celda
{
    public int Valor ;
    public Celda(int V){
        Valor = V;   
    }
    public Celda(){
        Valor = 0;
    }
    public override string ToString(){
        return "("+Valor+")";
    }   
}


public class Terreno
{
    Celda[,] _Matrix ;
    int Ancho, Alto;
    public Terreno(int px, int py){
        _Matrix = new Celda[px,py];
        Ancho = px;
        Alto = py;
    }
    public Celda LaCelda(int x, int y) {
        return _Matrix[x,y];
    }   
    public static void Main(){
        Terreno T = new Terreno(5,6);   
        for (int i=0; i<T.Ancho; i++)
        for (int j=0; j<T.Alto; j++)
            Console.WriteLine(T._Matrix[i,j].Valor);

    }   
}
</this>



when executing i get:
System.NullReferenceException: Object reference not set to an instance 
of an object

how shall i create my matrix?


thanks in advance.


--------------070107050805060409040400
Content-Type: text/x-vcard; charset=utf-8;
 name="bob.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="bob.vcf"

begin:vcard
fn:Phillip Neumann
n:Neumann;Phillip
email;internet:phillip@sofsis.cl
tel;cell:09-2750469
x-mozilla-html:TRUE
version:2.1
end:vcard


--------------070107050805060409040400--