Here we take the keyIndex column (int type) in table dt2 as an example
1. Implement it through linq
int maxKeyIndex = dt2.AsEnumerable().Select(t => t.Field<int>("keyIndex")).Max();
Linq syntax: click to open the link
2, implemented through the Compute method
int ee = (int)dt2.Compute("Max(keyIndex)", "true");
Compute method: click to open the link
3, implemented through the Select method
##
int rr = (int)dt2.Select("", "keyIndex DESC")[0]["keyIndex"];
Select method: Click to open the link4. Convert to List
Convert the columns that need to be sorted in the DataTable to List, and then use the Sort() of the list Method to sort, the default value is in ascending order, that is, after the sorting is completed, the last one in the list is the maximum value.
ListIntroduction
The above is the content of returning the maximum value in the column in C# DataTable, more related Please pay attention to the PHP Chinese website (m.sbmmt.com) for content!
##