Description
The following code is for implementing the least known feature of the DataTable, Compute() method. Furthermore, it shows how you can read data from the tab-delimited text file, and move this data into the DataTable object.
What does this method do?
It computes the given expression on the current rows that pass the filter criteria.
- object DataTable.Compute( string expression, string filter)
as you see, the function return "Object", so you have to cast it to your data type.
The following aggregate types are supported in an expression:
- Sum (Sum)
- Avg (Average)
- Min (Minimum)
- Max (Maximum)
- Count (Count)
- StDev (Statistical standard deviation)
- Var (Statistical variance)
I commented inline, so it should be very easy to follow. I programmed a simple windows application, so you can test it. Do not forget to change "FilePath"
Source Code: