C# reading CSV file to dictionary question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GTXY20
    New Member
    • Oct 2007
    • 29

    C# reading CSV file to dictionary question

    Hi all,

    I currently have a CSV file like so

    1,a
    1,b
    1,c
    2,a
    2,b
    2,b
    2,c
    3,a
    3,a

    I have used an application in Python whereby it reads the file using split with a comma value in a for loop and using the first field as a key in a dictionary and the second field added to a list which is the value for that key. For each line in the file I check to see if the first field item in the csv is in the current dictionary if not I create a key with that item and drop the second field otem into a list - I go through the complete file and where the key is already present I check the list (value for the key) to see if the second field from the CSV is present in the list, if present i do not add to list, if not I append to the list.

    So long story shory I end up with a dictionary like so:

    {1:[a,b,c], 2:[a,b,c], 3:[a}}

    Now I am looking to do the same thing in C# .Net - can anyone provide and guidance where I can start - I have done some looking for C# dictionary types but I am confused as to whether or not I can have a list as a value for the key and if so can I then iterate and sor the list once in a dictionary.

    Any suggestions are greatly appreciated.

    Thank you.

    GTXY20
Working...