指定演员表无效,请告诉我从数组中存储的所有值中获取最大/最小值的方法,而不是从特定索引中获取。
int max = jArray.Cast<int>().Max();
System.Console.Write("\n\n Max marks:" + max );
锯齿状阵列声明:
string TotalStudents;
System.Console.Write("Enter the 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][];
for (int i = 0; i < jag.noOfStudents; i++)
{
System.Console.Write("Enter the Total No. Of Subjects of Student:" + i + ":\t");
string TotalSubjects = Console.ReadLine();
int Subjectvalue;
bool Sresult = int.TryParse(TotalSubjects, out Subjectvalue);
jArray[i] = new int[Subjectvalue];
for (int a = 0; a < Subjectvalue; a++)
{
System.Console.Write("\nEnter the marks obtained of subject:" + a + " of student " + i + ":\t");
string TotalMarks = Console.ReadLine();
int Marksvalue;
bool Mresult = int.TryParse(TotalMarks, out Marksvalue);
jArray[i][a] = Marksvalue;
}
答案 0 :(得分:1)
JArray
是一个锯齿状数组(数组数组),这就是为int
特定转换为无效的原因。
我建议使用SelectMany
展平结构并查找Max
。
int max = jArray.SelectMany(x=>x.ToArray()).Max();