1

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?

3 Answers 3

9

You can use either

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

or

var result = from tenant in TenantList select tenant.ID
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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).
2
TenantList.Select(t => t.ID)

Comments

0
TenantList.Select(t => t.ID);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.