c# - Specified cast is not valid, getting all values from jagged array -
specified cast not valid, please tell me way max/min value values stored in array, not specific index.
int max = jarray.cast<int>().max(); system.console.write("\n\n max marks:" + max );
declaration of jagged array:
string totalstudents; system.console.write("enter total no. of students:"); totalstudents = console.readline(); int value; bool result = int.tryparse(totalstudents, out value); jaggedarray jag = new jaggedarray(value); int[][] jarray = new int[jag.noofstudents][]; (int = 0; < jag.noofstudents; i++) { system.console.write("enter total no. of subjects of student:" + + ":\t"); string totalsubjects = console.readline(); int subjectvalue; bool sresult = int.tryparse(totalsubjects, out subjectvalue); jarray[i] = new int[subjectvalue]; (int = 0; < subjectvalue; a++) { system.console.write("\nenter marks obtained of subject:" + + " of student " + + ":\t"); string totalmarks = console.readline(); int marksvalue; bool mresult = int.tryparse(totalmarks, out marksvalue); jarray[i][a] = marksvalue; }
jarray
jagged array(array of arrays), that's why specific cast int
invalid.
i suggest flatten structure using selectmany
, max
.
int max = jarray.selectmany(x=>x.toarray()).max();
Comments
Post a Comment