how can i sort array via linq?
if i trying to sort my columns return 0 valu. But i need max value descinding value but how?
for (int j = 0; j < dTable.Columns.Count; j++)
for (int i = 0; i < dTable.Rows.Count; i++)
{
mycounte开发者_StackOverflow中文版r[i] = dTable.Rows[i][j].ToString().Length;
}
mycounter = mycounter.OrderBy(i => i).ToArray();
mycounter.Reverse();
MessageBox.Show(mycounter[0].ToString());
I assume you want to sort in descending order. Just change OrderBy
to OrderByDescending
.
If you only need the maximum value, use the Max
extension method:
mycounter.Max()
精彩评论