I have an array which collects a name and a mark,I want to use a method to get the total of the array, I assume this can be done I have googled it but it doesn't really give me an answer.
heres Main
static void Main(string[] args)
{
Student[] sdt = new Student[5];
string carryOn = "n";
int choice = 0;
bool inMenu = false;
int recnum = 0;
while (!inMenu)
{
Console.WriteLine("Choose which account it you wish to use\n\n");
Console.WriteLine("1)Teacher");
Console.WriteLine("2)Student");
Console.WriteLine("3)Print Teacher details");
Console.WriteLine("4)Print Student Details");
Console.WriteLine("5)Quit ");
Console.Write("Enter your Selection: ");
try
{
choice = int.Parse(Console.ReadLine());
}
catch (FormatException)
{
}
Console.WriteLine();
switch (choice)
{
case 1:
{
}
break;
case 2:
{
int i = 0;
recnum = 0;
bool done = false;
while (!done && recnum <= 4)
{
Console.Write("Do you wish to enter a record?: ");
carryOn = Console.ReadLine();
if (carryOn == "y")
{
sdt[i] = new Student();
Console.Write("Enter a username: ");
sdt[i].Name = Console.ReadLine();
Console.Write("Enter a mark: ");
sdt[i].Mark = int.Parse(Console.ReadLine());
Console.WriteLine();
st.GetMark();
recnum++;
i++;
}
else
{
done = true;
}
}
}
break;
case 3:
{
}
break;
case 4:
{
for (int i = 0; i < recnum; i++)
{
if (sdt[i] == null)
{
Console.WriteLine("NO DATA");
}
else
{
Console.WriteLine(sdt[i].PrintStudent());
Console.WriteLine(st.GetMark());
}
}
}
break;
case 5:
{
inMenu = true;
}
break;
default:
{
}
break;
}
}
}