-3

I need to get the count of Employment for each Applicant in C# property, this is my code:

I am getting this error that not all the path return value what I need to change.

public class Application
{
    public int NumberOfEmpl {
        get
        {              
            foreach (var item in Applicants)
            {
                return Applicants == null ? 0 : (item.Employments.Count);
            }
        }
        set {}
    }
}
nick
  • 1,310
  • 8
  • 15
Alma
  • 3,780
  • 11
  • 42
  • 78
  • 1
    No idea what you are trying to do, but there are tons of questions about this error. – Alexei Levenkov Feb 24 '16 at 00:22
  • 1
    Don't make empty `set` accessors. – SLaks Feb 24 '16 at 00:22
  • `Applicants` cannot be null inside the loop. – SLaks Feb 24 '16 at 00:22
  • 1
    Aside from your misspelled error being easy to find information on, your code doesn't make any sense. Why would you want to return a value within a loop? Once you return a value, the getter terminates. That means you have a loop that could only every iterate once. – Jonathan Wood Feb 24 '16 at 00:39

1 Answers1

2

As the error is trying to tell you, you need to make sure your property always returns a value – even if the collection is empty.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964