Where do I look that up, Visual Studio edition?
July 3, 2018 8:37 AM   Subscribe

In a statement like this: var r = c.EnumerateColumns().Select(v => v.PointwiseMultiply(va)); where is the documentation for a statement in the parens following the Select?

Or, to put it another way, this

v => v.PointwiseMultiply(va)

is an example of what? What are the rules? What is it called? Where is the documentation?

For example, is it possible to have more than one expression? Would it work if, in this example, Pointwise was a void function, i.e.

public void PointwiseMuiltiply(){}
posted by SemiSalt to Computers & Internet (5 answers total)
 
Best answer: What language is this?

You should be able to pass any single argument function (of the appropriate type, anyway). Whether it can be a void should be documented with select. (I'm guessing it's a transformation of the result, so need to return something, but I'm just guessing.)

The term for the x=>pointwise(xa) is an "anonymous function".
posted by hoyland at 8:57 AM on July 3, 2018


Best answer: That's a lambda (a type of anonymous function), and with Select that's Linq.

You could do that with a void function, but Select is going to look for a bool return. At best nothing would happen, at worst the compiler would reject having the wrong return type, but that'd be due to the Select requiring it, not because of the usage of lambdas.

You might use a void return type with a .ForEach, like emailArray.ForEach(x => ProcessEmail(x))

Lambda Expressions (C# Programming Guide)

Basic LINQ Query Operations (C#) (this shows Linq expressions, which is kind of its own language, but you can write any of these in a lambda form as well)
posted by Nonsteroidal Anti-Inflammatory Drug at 9:04 AM on July 3, 2018 [4 favorites]


Response by poster: Thanks.

MS documentation is a great place to look up what you already know.
posted by SemiSalt at 9:10 AM on July 3, 2018


Actually Select doesn't take a bool, I don't know why I wrote that. Select actually wants Select<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)
posted by Nonsteroidal Anti-Inflammatory Drug at 9:12 AM on July 3, 2018 [2 favorites]


Practical note: Anonymous functions are inaccessible to your unit tests. Don't get too clever.
posted by j_curiouser at 10:57 AM on July 4, 2018


« Older More shirts like this one?   |   Safest affordable way to move from Toronto to... Newer »
This thread is closed to new comments.