c# - Can a ForEach lambda expression have an optional return type -
is there way foreach
lambda expression have optional return type. here pseudo code example of needs achieved:
string val = mylist.foreach(listitem => { if(listitem == "yes" ){ return "found" } }); if(val == "found"){ dosomething }
no, foreach
wrong method result. use any
:
bool found = mylist.any(listitem => listitem == "yes");
Comments
Post a Comment