c# - Select fails to print to console -
i hoping utilize select
functional foreach. when following, expected print
foo bar baz
it doesn't print however. howcome? code is
list<string> strings = new list<string>(){"foo", "bar", "baz"}; strings.select(st => { console.writeline(st); homecoming 1; });
use foreach:
list<string> strings = new list<string>() { "foo", "bar", "baz" }; strings.foreach(st => { console.writeline(st); });
by using select you're defining anonymous functions next body.
console.writeline(st); homecoming 1;
so, console.writeline triggered when you're iterating through list, this:
var x= strings.select(st => { console.writeline(st); homecoming 1; }); foreach (var in x){ }
or x.tolist()
and wrong, utilize foreach :)
c# linq select
No comments:
Post a Comment