LINQ is just a bunch of specialized iterations.
At the end of the day, your extension method call Selectlooks something like this:
foreach(Person person in persons)
{
yield return person.Address;
}
... and therefore you get a set of strings where there is one nullítem.
On the other hand, if you want to filter the sequence so that you don't get a collection with nulllinks, what would you do without LINQ? Maybe something like this:
foreach(Person person in persons)
{
if(person.Address != null)
yield return person.Address;
}
... And in the LINQ world Where, then Select:
persons.Where(person => person.Address != null).Select(person => person.Address);
source
share