You have a data table and you need to group and sum records dynamically.
I needed to group information by a field and the sum the values on a different field;
For example, I want to group employees by department and then sum their salary.
Below is the linq code to this:
PivotFieldName is the name of the department field on the data table
FieldName is the name of the salary field on the data table
For VB.Net you can use anonymous types to set field type and dynamically set it at run time.
For C#, you cannot replace the value of the field type at run time, so for now, I am just using integer. For more numeric types, or string types, we have to create an Interface and then Implement a Strategy / Pattern design/