class ReadGradesIn
{
public void readGrade()
{
int numberOfA = 0; //number of A grades
int numberOfB = 0;//number of B grades
int numberOfC = 0;//number of C grades
int numberOfD = 0;//number of D grades
int numberOfE = 0;//number of E grades
int numberOfF = 0;//number of F grades
string lineOfData;//value given to this variable is what it is reading from file
TextReader grades = new StreamReader("grades.dat"); //read grades in
lineOfData = grades.ReadLine();
while (lineOfData != null) //start while loop until lineofdata is null
{
lineOfData = grades.ReadLine();
switch (lineOfData) //start switch statement
{
case "A":
numberOfA++;
break;
case "B":
numberOfB++;
break;
case "C":
numberOfC++;
break;
case "D":
numberOfD++;
break;
case "E":
numberOfE++;
break;
case "F":
numberOfF++;
break;
}//end switch statement
}//end while loop
int numOfGrades = numberOfA + numberOfB + numberOfC + numberOfD + numberOfE + numberOfF;
grades.Close(); //close textreader
Console.ReadLine();
}//end method readGrade
}//end class
Hi everyone, new here. Basically what I am trying to achieve is to be able to access the variable numberOfA , numberOfB, numebrOfC, numberOfD from another class. I am fairly new to C# and thought the best way to do this would be to put a switch statement in. I am reading grades (a,b,c,d,e,f) in from a .dat file but would like to keep all the above in a seperate class, the only problem is how I access the values in the variables, hope this makes sense,
Many Thanks in advance...