Return the maximum value in a column in C# DataTable

黄舟
Release: 2017-02-16 10:44:06
Original
1950 people have browsed it

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();
Copy after login

Linq syntax: click to open the link
2, implemented through the Compute method

int ee = (int)dt2.Compute("Max(keyIndex)", "true");
Copy after login

Compute method: click to open the link
3, implemented through the Select method

##

int rr = (int)dt2.Select("", "keyIndex DESC")[0]["keyIndex"];
Copy after login

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 (www.php.cn) for content!


##

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!