Help writing to a file is there is a double. (Help)

Hi I don't know if i'm in the correct sub reddit or not but I was wondering if someone could point me in the right direction. The problem is I need to take in 50 names from a text document and find the highest mark, but when I go to write it to a new file then nothing will appear or will only print one name if two students have the same mark.

static void write_max(results[] studentResults, int maxMark) { for (int i = 1; i < 50; i++) { if (studentResults[i].Mark>maxMark) { System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\richard\Desktop\Programing\MaxResults.txt"); file.WriteLine(studentResults[i].Name + " " + maxMark); file.Close(); } }

This is my code to print the max result plus the student name. If anyone could help me that would be amazing, thank you for your time:)

by blink95 via /r/csharp

Leave a Reply