views:

65

answers:

1

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++)
                {
                    mycounter[i] = dTable.Rows[i][j].ToString().Length;
                }
            mycounter = mycounter.OrderBy(i => i).ToArray();

            mycounter.Reverse();
            MessageBox.Show(mycounter[0].ToString());
+6  A: 

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()
Mehrdad Afshari
Was going to ask the OP to clarify but answering both possible questions is a good approach. :)
Mayo