在getter / setter C#property

时间:2016-02-24 00:19:39

标签: c#

我需要在C#属性中获取每个申请人的就业人数,这是我的代码:

我收到此错误,并非所有路径返回值都需要更改。

public class Application
{
    public int NumberOfEmpl {
        get
        {              
            foreach (var item in Applicants)
            {
                return Applicants == null ? 0 : (item.Employments.Count);
            }
        }
        set {}
    }
}

1 个答案:

答案 0 :(得分:2)

由于错误试图告诉您,您需要确保您的属性始终返回一个值 - 即使该集合为空。