I need a multi dimensional (Jaged Array) for entering Matrix data. Can any body telll whats wrojng with the code I have attched here...
a=new int[m][];
for(i=0;i
Console.WriteLine("No. Of Cols: in Raw "+(i+1));
n=Convert.ToInt32(Console.ReadLine());
for (j=0;j
Console.WriteLine("Enter cl: "+(j+1));
a[i][j]=Convert.ToInt32(Console.ReadLine());
}
}
for( i=0;i
for ( j=0;j {
Console.Write(a[i][j]+"\t");
}
Console.WriteLine("\n");
}
}
}
Error Message while executing the progrma:"Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at MyArrayc2.Main()"
anish knPosted Oct 14, 2007, 8:18 AM
Thank you very much... now everithing works well
AlanPosted Oct 13, 2007, 8:30 AM
The problem is that you've forgotten to initialize the 'm' arrays in the jagged array. Change the first bit of code to this and all should be well:
a = new int[m][]; {
{
for(i=0;i
Console.WriteLine("No. Of Cols: in Raw "+(i+1));
n=Convert.ToInt32(Console.ReadLine());
a[i] = new int[n]; // added this line
for (j=0;j
Console.WriteLine("Enter cl: "+(j+1));
a[i][j]=Convert.ToInt32(Console.ReadLine());
}
}