c# - Refer variable from different class -


using system;  namespace matrix_algebra {     public struct s_matrix_size     {         public int size_r, size_c;         public s_matrix_size(int r, int c)         {             this.size_r = r;             this.size_c = c;         }     }      public class c_matrix_entries     {          public c_matrix_entries()         {             int r, c;             console.writeline("enter number of rows , columns ");              r = convert.toint32(console.readline());             c = convert.toint32(console.readline());              s_matrix_size size = new s_matrix_size(r,c);              double[,] entry = new double [size.size_r,size.size_c];              console.writeline("enter entries first row [left right] last row ");             (int = 0; i<size.size_r; i++)             {                 console.writeline("enter {0} row", + 1);                 (int j = 0; j<size.size_c;j++)                 {                     entry[i, j] = convert.todouble(console.readline());                 }             }                }           } }  namespace row_reduce_algebra {     using matrix_algebra;     public class test     {         static void main()         {             c_matrix_entries matrix_no1 = new c_matrix_entries();             (int = 0; < **matrix_no1.size**; i++)             {              }         }     } } 

as title says, i'm trying access variable class instance, don't know how properly.

as @grantwinney rightfully pointed out (as shaping working reply you), cannot access matrix_no1.size because inaccessible. (it out of scope being matrix_no1 local variable declared in default c_matrix_entries constructor.)

based on code, here end-to-end working example of how fix problem using different public property added c_matrix_entries. beyond flavor of new s_matrix_size public property add c_matrix_entries (i.e. grant winney's work too), need compute product of size_r , size_c properties in loop's setup.

using system;  namespace matrix_algebra {     public struct s_matrix_size     {         public int size_r, size_c;         public s_matrix_size(int r, int c)         {             this.size_r = r;             this.size_c = c;         }     }      public class c_matrix_entries     {         private s_matrix_size _size;          public c_matrix_entries()         {             int r, c;             console.writeline("enter number of rows , columns ");              r = convert.toint32(console.readline());             c = convert.toint32(console.readline());             _size = new s_matrix_size(r,c);              double[,] entry = new double [_size.size_r,_size.size_c];              console.writeline("enter entries first row [left right] last row ");             (int = 0; i<_size.size_r; i++)             {                 console.writeline("enter {0} row", + 1);                 (int j = 0; j<_size.size_c;j++)                 {                     entry[i, j] = convert.todouble(console.readline());                 }             }                }              public s_matrix_size size { { return _size; } }     } }  namespace row_reduce_algebra {     using matrix_algebra;     public class test     {         static void main()         {             c_matrix_entries matrix_no1 = new c_matrix_entries();             (int = 0; < matrix_no1.size.size_r * matrix_no1.size.size_c; i++)             {                 // todo: useful                 console.writeline(i); // fornow             }          }     } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -