There is an array of DataRow[] datarows . One of the columns is called Sum . How to get the maximum value for this column using the LINQ extension? Thank.
|
1 answer
If we leave aside the fact that you are working with an array of DataRow , and answer specifically the question, then the search for the maximum element will not be very different from the search for an element in the array containing objects of a particular class.
You can access DataRow columns using indexers (by column name or index (count from 0)), which return an object of type.
You can also add a link to System.Data.DataSetExtensions.dll and use Field extension methods that provide strongly typed access to your columns.
Thus, your code will be approximately as follows:
var max = datarows .Select(x => x.Field<int>("Sum")) .Max(); |
Dapperfor this task (in fact, these are extensions for ADO.NET), because working with pure ADO.NET is not as effective. - Vadim Ovchinnikov