By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

C# reading CSV file to dictionary question

GTXY20
P: 29
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
Apr 5 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.