KeyValuePair Dictionaries Help
I provided the source code, it basicly retrieves data from a file and read that file store it into a List then outputting it by using KeyValuePair
Below is where I am currently at, and final output, the difference is "Author Name: " and final output is "Author Name: Bruna Martinuzzi" (with respective order)
It will output like this but im dont know how to start by creating an Authors Dictionary. I need to enable cross referencing between authors.csv and books.csv data files and parse the data from each line of the authors.csv file and store it in an Author object. store each author object in a dictionary collection named authors. then when initialiizing the Book object look up the author's first and last names from this Dictionary
Department Name: Clothing
Floor: 2
Price: 23.44
Price with taxes: 26.72
Product: tennisT by Nike
Department Name: Clothing
Floor: 2
Price: 42.35
Price with taxes: 48.28
Product: Sweat Top by Reebok
Department Name: Clothing
Floor: 2
Price: 38.99
Price with taxes: 44.45
Product: Khaki Casuals by LaCoste
Department Name: Reading
Floor: 1
Price: 12.78
Price with taxes: 13.67
Title: The Leader as a Mensch
Publisher: Six Seconds
Author Name:
Department Name: Reading
Floor: 1
Price: 23.44
Price with taxes: 25.08
Title: Software Teamwork: Taking Ownership for Success
Publisher: Addison-Wesley Professional
Author Name:
Department Name: Reading
Floor: 1
Price: 45.99
Price with taxes: 49.21
Title: ASP.NET MVC 1.0
Publisher: Wrox Press
Author Name:
Department Name: Reading
Floor: 1
Price: 7.54
Price with taxes: 8.07
Magazine Name: Wired
Issue Month: September Issue Year: 2010
Department Name: Reading
Floor: 1
Price: 5.88
Price with taxes: 6.29
Magazine Name: PC World
Issue Month: September Issue Year: 2010
But I want to get it like this
Department Name: Clothing
Floor: 2
Price: 23.44
Price with taxes: 26.72
Product: tennisT by Nike
Department Name: Clothing
Floor: 2
Price: 42.35
Price with taxes: 48.28
Product: Sweat Top by Reebok
Department Name: Clothing
Floor: 2
Price: 38.99
Price with taxes: 44.45
Product: Khaki Casuals by LaCoste
Department Name: Reading
Floor: 1
Price: 12.78
Price with taxes: 13.67
Title: The Leader as a Mensch
Publisher: Six Seconds
Author Name: Bruna Martinuzzi
Department Name: Reading
Floor: 1
Price: 23.44
Price with taxes: 25.08
Title: Software Teamwork: Taking Ownership for Success
Publisher: Addison-Wesley Professional
Author Name: Jim Brosseau
Department Name: Reading
Floor: 1
Price: 45.99
Price with taxes: 49.21
Title: ASP.NET MVC 1.0
Publisher: Wrox Press
Author Name: Scott Guthrie
Department Name: Reading
Floor: 1
Price: 7.54
Price with taxes: 8.07
Magazine Name: Wired
Issue Month: September Issue Year: 2010
Department Name: Reading
Floor: 1
Price: 5.88
Price with taxes: 6.29
Magazine Name: PC World
Issue Month: September Issue Year: 2010
Gomathi PalaniswamyPosted Oct 8, 2010, 1:18 AM
am not get your question correctly.i mentioned one link below that article will used to create the dictionary with key and value.
http://dotnetperls.com/dictionary-keys
David ChenPosted Oct 8, 2010, 12:55 AM
oh hashtable, i dont think we are covering that
but i think we are trying to use TryGetValue() sort of similar what you did, authorName ["sw8269"].
umm...
Bryian TanPosted Oct 8, 2010, 12:43 AM
Hello,
I'm not sure if I get your question correctly, but please correct me if I'm wrong. Please refer back to this post http://www.c-sharpcorner.com/Forums/UploadFile/96276/
Move the codes in the AddBooks method to a new method and store the Author information in the HashTable. To retrieve the author name:
Hashtable authorName = Authors();
authorName ["sw8269"] // return Scott Guthrie
Now, you need to figure out how to implement the rest of it. Since this is your homework, I can't show you the complete solution.
static Hashtable Authors()
{
Hashtable author = new Hashtable();
//get the authors from authors.csv
string[] authors = Reader.ReadLines(PathMgr.AUTHORS_FILE);
string[] authorDetail;
string authorName = string.Empty;
for (int a = 0; a < authors.Length; a++)
{
//author book identifier abcef123,
//author last and first name Martinuzzi, Bruna
authorDetail = authors[a].Split(",".ToCharArray());
authorName = authorDetail[(int)Reader.eAuthors.firstName] + authorDetail[(int)Reader.eAuthors.lastName];
author.Add(authorDetail[(int)Reader.eAuthors.random], authorName);
}
return author;
}