Problem when exchanging rooms C #

0

Now I have my next question! in c # I have a declared public global matrix

 public string[,] matriz=new string[3,4];

Now, create a module called public void llenar() to fill the matrix, but to access the module I must create a new instance of the project class.

program llen = new program();
    program.llenar();

all right up there I fill the matrix and everything, just that there is a detail, create a module to show the matrix public void show matrix (); there it shows me the matrix, but before calling it I must recreate another instance

program ver= new program();
ver.mostrarmatrizr();

Behold, the matrix appears empty to me. as if I had never filled it. because that happens to me

    
asked by Moises Jota 03.08.2017 в 19:52
source

1 answer

0

Being different instances, its members have different values, that's why it appears empty.

You can declare the variable matrix as static, it will work for you as you need it and you do not need to make instances of the program, but only send it as program.matriz :

public static string[,] matriz=new string[3,4];
    
answered by 03.08.2017 в 20:01