C# 2D Arrays read from keyboard error -


i have error: "unhandled exception: system.nullreferenceexception: object reference not set instance of object." on line "v[i][j]=convert.toint32(console.readline());" kinda new object oriented languages, , not sure means. thanks!

static void main(string[] args) {     int m, n, i, j;     int[][] v=new int[10][];     n=convert.toint32(console.readline());     m=convert.toint32(console.readline());     for(i=0;i<n;i++)        for(j=0;j<m;j++)        {           console.writeline("v[{0}][{1}]= ", i, j);           v[i][j]=convert.toint32(console.readline());        }     for(i=0;i<n;i++)     {        for(j=0;j<m;j++)           console.writeline("{0} ", v[i][j]);        console.writeline();     } } 

i think need change this:

int[][] v=new int[10][]; 

because code doesn't reserve memory 2d array.

it should be:

        int m, n, i, j;         n = convert.toint32(console.readline());         m = convert.toint32(console.readline());         int[,] v = new int[n,m];         (i = 0; < n; i++)             (j = 0; j < m; j++)             {                 console.writeline("v[{0}][{1}]= ", i, j);                 v[i,j] = convert.toint32(console.readline());             }         (i = 0; < n; i++)         {             (j = 0; j < m; j++)                 console.writeline("{0} ", v[i,j]);             console.writeline();         } 

you can show this tutorial multidimensional arrays microsoft.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -