How to represent tabular data in C# which has generic datatypes in a variable number of columns? -


i have following c# solution using generics representing tabular data has different datatypes in each column. ultimate goal compare datapoints of 2 tables, why columns have constraint implement icomparable. difficulty in scaling can support number of columns user wishes:

class tableobject<rowheadertype, column1type, column2type>     column1type : icomparable     column2type : icomparable {     list<string> columnheaders;     dictionary<rowheadertype, dictionary<string, icomparable>> tabledict;     dictionary<string, icomparable> rowdict;      public tableobject(list<string> _columnheaders)     {         tabledict = new dictionary<rowheadertype, dictionary<string, icomparable>>();         columnheaders = _columnheaders;      }      public void addrow(rowheadertype rowheader, column1type colvalue_1, column2type colvalue_2)     {         // rowdict represents 1 row, each key/value representing column of data         rowdict = new dictionary<string, icomparable>();          rowdict.add(columnheaders[1], colvalue_1); // [0] row header table          rowdict.add(columnheaders[2], colvalue_2);          // add new row master table         tabledict.add(rowheader, rowdict);     }  } 

in constructor pass in list column labels. call addrows take (ideally) rowheadertype value, , array represent values make entire row, each corresponding columntype defined.

my goal make generic possible. restriction have here column names strings since wish display in datagridview.

if there alternate design feel better, please feel free suggest well. thanks.

do know datasets, datatables, datacolumns , datarows?

you can work typed data sets. there's lot of existing support them.


Comments