C# 2D array with string keys and int values -


i'm trying create data structure looks following:

             xls | doc | ppt | pdf            |--------------------- app/xls    |  1  |  0  |  0  |  0   app/msword |  1  |  1  |  0  |  0 app/ppt    |  0  |  0  |  1  |  0 app/pdf    |  0  |  0  |  0  |  1 

basically have list of lists in have information like:

[ext, xls], [mime, app/xls] [ext, ppt], [mime, app/ppt] [ext, doc], [mime, app/msword] [ext, xls], [mime, app/msword] 

note extension doesn't match appropriate mime value. reason wanting output table able see graphically distribution of extensions not mapped correct mime.

so can loop through list of lists , access each document both ext , mime, can't head around how extract/store hence output information in tabular form. have dictionary of correct ext-mime, important ensuring diagonal line top-left of table bottom-right, place should have non-zero values if data correct (because order of column-row matters in case).

so go here?!

if understand question, looping through bunch of data , populating numbers (0's , 1's, 2's.. n++) in above structure.

without getting fancy, i'd use

d = new dictionary<string, dictionary<string, int>>();    

if wanted fancy, i'd create class had following:

  • a list of horizontal keys seen far
  • a list of vertical keys seen far
  • a dictionary of "key1#key2" value of 0|1|2...
  • a "setter" of (key1,key2) => add horizontal keys and/or vertical keys if doesn't exist
  • a "getter" of (key1,key2) => retrieves value out of dictionary

this allow pull out in nice pretty grid minimal effort, while maintaining decent write speed. let sort rows / columns in whichever way want. if added "optimalmapping" let know mimetype maps extension, can add check see if optimal or not.


Comments

Popular posts from this blog

Java sticky instances of class com.mysql.jdbc.Field aggregating -