2016-06-11 6 views
0

지정된 캐스트가 유효하지 않습니다. 특정 인덱스가 아니라 배열에 저장된 모든 값에서 최대/최소값을 얻는 방법을 알려주십시오. 가변 배열의지정된 캐스트가 유효하지 않음. 지그재그 배열에서 모든 값 가져 오기

int max = jArray.Cast<int>().Max(); 
       System.Console.Write("\n\n Max marks:" + max); 

선언 : int 특정 캐스트가 유효하지 않은 이유를

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; 

      } 

답변

1

JArray는 가변 배열 (배열의 배열), 그입니다.

SelectMany을 사용하여 구조를 평탄화시키고 Max을 찾으십시오.

int max = jArray.SelectMany(x=>x.ToArray()).Max();