找到最大的数字

时间:2014-01-14 06:03:38

标签: c#

有人可以帮我找到最多的字符串吗?这是代码:

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)
         {

         }
}

由于

1 个答案:

答案 0 :(得分:2)

你可以在单行

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