c# - Linq Select why am I getting a result? -


i getting strange result linq query don't understand:

public class person  {     public address address { get; set; }     public string name { get; set; }     ... } 

imagine have icollection<person> 1 entry , person having address null

when following linq statement:

var test = person.select(x => x.address).tolist(); 

the test variable list 1 entry null.

  • why 1 null entry instead of empty list?
  • what have change empty list?

thanks in advance

why 1 null entry instead of empty list?

because select projection , give result of adress null

from msdn

projects each element of sequence new form. 

what have change empty list?

 var test = person.where(x => x.address != null).select(x => x.address).tolist(); 

or in linq query expression

var t = p in person                 p.adresse != null                 select p.adresse; 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -