Can someone explain why the following line of C# doesn’t behave the same as the following foeach block?
string [] strs = {"asdf", "asd2", "asdf2"};
strs.Select(str => doSomething(str));
foreach(string str in strs){
doSomething(str);
}
I put a breakpoint inside of doSomething() and it doesn’t fire in the Select but it does with the foreach.
TIA
The
Linqquery won’t be processed until you convert it to anEnumarableusingToList(),ToArray(), etc.And by the way the equivalent to your
foreachstatement is something like this:or