2010-06-20 5 views
-1

내 바보 문제를 돕기 위해 행크스에 온 사람들 (내 게시물을보세요 :)). 하지만 정확히 아래에 필요합니다. 나는 세포 Datatable의 legth에서 1 dimentional 배열을 작성해야합니다. 정렬 1D 배열 linq 또한 linq없이어떻게 2D 배열에서 1D 배열을 채울 수 있으며 1D 배열을 정렬 할 수 있습니까?

int[][] lengths; 

      using (DataTable table = GetTable()) 
      { 
       lengths = (from DataRow row in table.Rows 
          select 
          (from DataColumn col in table.Columns 
          select row[col].ToString().Length).ToArray()).ToArray(); 
      } 

      int[] Sortedlist; 
      foreach (int[] row in lengths) 
      { 
       Sortedlist = row; ---- I NEED HELP !!!! 
      } 

      foreach (int item in Sortedlist) 
      { 
       item.Sort(); ----- I NEED HELP!!! 
      } 

My Data:

static DataTable GetTable() { // // Here we create a DataTable with four columns. // DataTable table = new DataTable(); table.Columns.Add("Dosage", typeof(int)); table.Columns.Add("Drug", typeof(string)); table.Columns.Add("Patient", typeof(string)); table.Columns.Add("Date", typeof(DateTime)); // // Here we add five DataRows. // table.Rows.Add(25, "Indocin", "David", DateTime.Now); table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now); table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now); table.Rows.Add(21, "Combivent", "Janet", DateTime.Now); table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now); return table; }

답변

0

무슨 뜻인지 확실하지 않습니다. 당신은 int [] [] 데이터 구조 (주요 linq 쿼리에서). req는 int [] 구조체로 변환 한 다음 linq을 사용하여 정렬하고 Array.sort를 사용하여 정렬합니다. 해야합니다

int[] UnSortedlist = lengths.SelectMany(x => x).ToArray(); 
      int[] sortedListLinq = UnSortedlist.OrderBy(x => x).ToArray(); 
      Array.Sort(UnSortedlist); 
      int[] sortedListnonLinq = UnSortedlist; 
+0

내가 좋아하는 : Array.Sort (UnSortedlist); int [] sortedListnonLinq = 정렬되지 않은 목록; 그러나 Reverse() 메소드처럼 내림차순을 사용할 수 있습니까? – Penguen

관련 문제