0

If i have the expression:

from p In Product Select p.Name

i understand that p is an Element of Products.

If i have:

Dim allProducts = Products.Select(Function(p) p.Name)

my question is how do i say here that p is an Element of Products?

4
  • 2
    There is no k. Only p. Commented Sep 6, 2013 at 8:29
  • corrected typing error sorry Commented Sep 6, 2013 at 8:30
  • @ruedi: The question is not clear. Basically there is no difference between p in the query syntax and p i the method syntax. Commented Sep 6, 2013 at 8:32
  • I just try to understand when i say p IN Product... i understand that p is an element of Product. As when i say for each x IN Y. But in the lambda Expression above p is also an element of Products but i just cannot see how this happens. Commented Sep 6, 2013 at 8:35

1 Answer 1

2

Because the VB.NET compiler uses Type inference

Thanks to that, the types of the parameters and of the return value of the anonymous method Function(p) p.Name are discovered through the analysis of the signature of .Select() first (to discover the type of p) and then of the type of p.Name (to discover the return value type)

From Basic Instincts: Lambda Expressions

The introduction of powerful type inference mechanisms means that you don't need to worry about figuring out the type of each variable.

and so on... It's quite long.

Sign up to request clarification or add additional context in comments.

1 Comment

good explanation, i didnt get how the types are discovered, now i have it. helps a lot, thank u!

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.