I have started learning c# just over 3 months so for homework I have an exercise where i have to read from a text file with 50 names and marks. I have to find the name with the highest mark display it and save the result to a text file.This is what I have come up with.
namespace FINAL
{
class Program
{
public static string [] parts;
struct StudentDetails
{
public string name;
public string surname;
};
struct CourseWorkResults
{ public int mark;
};
static void Main(string[] args)
{
string [] Lines = System.IO.File.ReadAllLines(@"F:\FINAL\StudentExamMarks.txt");
foreach (string line in Lines)
{
string[] parts = line.Split();
}
StudentDetails[] Student = new StudentDetails[50];
CourseWorkResults[] Results = new CourseWorkResults[50];
GetName( ref Student ,ref parts );
FindMark ( ref Results , parts);
FindMax (ref Results);
}
static void GetName(ref StudentDetails[]Student, ref string[] parts)
{
for (int i = 0; i < Student.Length; i++ )
{
Student[i].name = parts[0];
Student[i].surname = parts[1];
}
}
static void FindMark ( ref CourseWorkResults[]Results, string [] parts )
{
for (int i=0; i< Results.Length;i++)
{
Results[i].mark = Convert.ToInt16(parts[2]);
}
}
static void FindMax( ref CourseWorkResults[]Results)
{
for (int i = 0; i < Results.Length; i++)
{
int max = 0;
max = Results[2].mark;
if (Results[i].mark > max)
{
max = Results[i].mark;
}
}
}
static void DisplayResults( ref CourseWorkResults[]Results, StudentDetails[]Student, int max)
{
Console.WriteLine(" The student with the highest score is {0} {1} :{2}", Student[0].name, Student[1].surname, max);
}
}
}
My problem is the GetName procedure , I can't pass by reference parts. What am I doing wrong?