2014-01-14 42 views
-5

請有人能幫我找到最多的一個字符串?下面的代碼:找到最大編號

if (dt.Rows.Count > 0) 
{ 
    int max = 0; 
    foreach (DataRow dr in dt.Rows) 
    { 
     bookNo = dr.ItemArray[0].ToString(); 
     int i = Convert.ToInt32(bookNo.Substring(bookNo.Length - 1)); 
     if (i > max) 
     { 

     } 
} 

感謝

+4

首頁工作不允許 –

+0

便於你這樣做在SQL太 –

回答

3

你可以做到這一點的一個班輪

int max = dt.Rows 
      .Select(x=>Convert.ToInt32(x.ItemArray[0].ToString().Substring(bookNo.Length-1))) 
      .Max();