How do I find that max/min value of a cell in a DataTable (C#)
Posted on 2009-05-02
I'm looking for a way to find the min/max value of a group of cells in a DataTable, regardless of the datatype of the specific columns. I could be given a DataTable populated with cells of various datatypes (int32, decimal, double, ...).
For example, I could be given the following:
| 10 | 83 | 21 |
| 22 | 17 | 92 |
| 42 | 33 | 89 |
Or for example:
| 3.2 | 9.1 | 6.8 |
| 1.2 | 7.5 | 8.3 |
Surely there is a way to do this in a fashion more automated than checking the 'type' of the column and using the specific System.Convert function? Ideally the result should be returned in the datatype of the cells in the table.
I went down a path of creating a class for each datatype, and doing class specific interpretation -- but that doesn't feel right.