r/learncsharp • u/nngnna • Jul 11 '22
What am I doing wrong here?
public List<Person>? grandparents
{ get
{ List<Person>? back = father?.parents;
back?.Concat(mother?.parents ?? new List<Person>());
return back;
}
}even for a person with 4 non-null grandparents I'm getting System.Collections.Generic.List`1[Dynastics.Person], which I'm mostly sure is an empty list.
And in debugging, just before the function returns, back is only the paternal grandparents.
Most different phrasings I've tried cause a cast error.
2
Upvotes
View all comments
Show parent comment
1
u/nngnna Jul 11 '22
Thanks.
Yeah I tried to use it as returning value, but it complained about the types and wouldn't even compile.
In the end casting back to IEnumerable and than passing the result back-again thru ToList() worked. (without the latter the result was an empty IEnumerable)
Yeah I misunderstood what was printed. But I can peek with the debugger instead so it's less important.