tags:

views:

71

answers:

4

I have a list of Tenants (call it TenantList), and it's composed of Tenant objects and they all have an ID property. How can I return an enumerable item composed of their ID properties?

+2  A: 
TenantList.Select(t => t.ID)
VirtualBlackFox
A: 
TenantList.Select(t => t.ID);
James Curran
+6  A: 

You can use either

var result = TenantList.Select(t => t.ID)

or

var result = from tenant in TenantList select tenant.ID
Nader Shirazie
What's the difference?
Malfist
There's no difference. The query syntax is actually transformed into the extension method syntax under the covers. They're just different ways of expressing the same query. As you get more comfortable with linq, you will find that one or the other is more appropriate, depending on the context.
Nader Shirazie
Syntactic sugar. The second form gets "preprocessed" into the first form when the code is compiled (shamelessly ripped off from Jon Skeet's C# in Depth).
Eric
+1  A: 
TenantList.Select(t => t.ID)
dkson