IEnumerable <dynamic> linq expressions

I have a dynamic customer list IEnumerable<Customer>

Now I want the names of those removed from this list to be named?

I thought I could do something like

 dynamic cur = (from c in result.Customers
                      select g.CompanyName).Distinct();

but today I learned that I can’t ... how can I build such a request?

+3
source share
2 answers

As long as the class Customerhas a member CompanyName, you can do the following:

var companies = (from c in result.Customers
                 select c.CompanyName).Distinct();

There is no advantage to using the keyword dynamiccompared to varhere, except that it will prevent compiler errors.

+4
source

, , , , - .

IEnumerable<dynamic>, :

IEnumerable<dynamic> cur = (from c in result.Customers
               select g.CompanyName).Cast<dynamic>().Distinct();

from c in result.Customers select g.CompanyName IEnumerable<string>.
Cast<dynamic>() IEnumerable<dynamic>.
Distinct() .

Distinct() EqualityComparer <T> . , , , ( ).

, , , . , .

+5

All Articles