Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i produce the following table below in csv format without duplicated string for student's name. I did try hashset class but that didn't work for me.

student's Name Grade Subject

A passed math
passed science
failed art

B passed math
passed science
failed art

A passed math
passed science
failed art
Posted
Updated 9-Sep-13 12:23pm
v2
Comments
Sergey Alexandrovich Kryukov 9-Sep-13 19:25pm    
Your "that did not work for me" is not informative at all. Please see my answer. If this is not your concern, ask your follow-up questions.
—SA

Good idea. Use HashSet, but the way it would help you. This class does not allow duplicates. What's the problem? Do you want to preserve order? If this is the problem, use both list, to keep order, and HashSet, to keep uniqueness. Got the idea? This is a really simple thing.

—SA
 
Share this answer
 
v2
Comments
Philip Tia 9-Sep-13 20:03pm    
What i am doing it right now is, which resulting in

student's Name Grade Subject

A passed math
passed science
failed art

B passed math
passed science
failed art

passed math /*student name 'A' is missing*/
passed science
failed art

public static HashSet<string> compareString = new HashSet<string>();

string[] student_name= {'A','B','A'};

if (compareString.Contains(student_name))
{
student_name= "";
}

compareString.Add(student_name);
Sergey Alexandrovich Kryukov 9-Sep-13 20:07pm    
You don't need all that. Look:
if (!myHash.Contains(line)) {
myHash.Add(line);
myList.Add(line);
}
—SA
Joezer BH 10-Sep-13 3:29am    
5ed!
Sergey Alexandrovich Kryukov 10-Sep-13 10:39am    
Thank you.
—SA
In your requirement, you have a student who have a pass/fail status in several subjects.
So create a Dictionary< [string student], [Dictionary< [string subject], [string status]> ] >

Then you can iterate over main dictionary, print out the student name, and then iterate over inner dictionary and iterate over the subject/status combination.

The Dictionary will override existing values when u insert a duplicate, so be aware of spelling mistakes

Note that the above code is not actual code, just an illustration of design and which field go in where...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900