Tried this and it gives me an "unassigned local variable" on the return returnvalue;
public bool enrolCheck(Paper p, Student s)
{
bool returnvalue;
for (int i = 0; i < papersEnrolled.Count; i++)
{
string names = papersEnrolled[i].ToString();
if (names == p.ToString())
{
returnvalue = true;
}
}
return returnvalue;

3 answers
Add an else statement also....
now try
answered one year ago by:
412
You need to provide a default value for returnvalue (otherwise if names == p.ToString() is false, returnvalue will never have a value).
You can do this in 2 ways, either provide an else block to the if condition of alternitivly, set a default value when you create the returnvalue variable which will then assume false (unless the if condition is true).
bool returnvalue = false;
answered one year ago by:
480
It looks to me that, as well as the 'unassigned local variable' error, you also have two other issues in this method.
If you're checking that a student is enrolled for a particular paper, once you've found that paper in the papersEnrolled list you should return 'true' straightaway rather than continuing the for loop.
The Student parameter, s, is never used and could therefore be eliminated.
Addressing these issues would enable you to simplify your method as follows:
answered one year ago by:
17279