C# Linq and lambda -


how select(int.parse) work in such linq expression?

"1,2,3,4,5".split(',').select(int.parse).tolist();                 //ok "1,2,3,4,5".split(',').select(x => int.parse(x)).tolist();         //ok 

why example console.writeline returns compilation error?

"1,2,3,4,5".split(',').select(console.writeline).tolist();         //error "1,2,3,4,5".split(',').select(x => console.writeline(x)).tolist(); //ok 

when allowed omit lambda (x => ....(x))

console.writeline int.parse so-called method groups. groups of methods. because of various overloads of methods. can 1 method, or multiple methods.

a method group can converted delegate if compiler can infer method of group meant. example method group int.parse can delegate int.parse(string) if func<string, int>is expected.

this works in first example. select expects func<t, t2> , t set of type string. however, not work second example. because while console.writeline method group, not single method in group corresponds required func<t, t2> because return type of all of methods in group void.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -