I have two lists of the same type and I want to be able view a list of both lists:
public List<Page> HeaderPages;
public List<Page> SurveyPages;
public IReadOnlyList<Page> AllPages
{
get
{
List<Page> allPages = new List<Page>();
allPages.AddRange(this.HeaderPages);
allPages.AddRange(this.SurveyPages);
return allPages;
}
}
I think it is very inefficient to keep creating a new list object each time I want to get AllPages
, so I thought I could store a private allPages
list. But then I thought if I am in the class, I would have to remember to use the public AllPages
rather than the private allPages
- which may not be up-to-date.
Any elegant solutions?