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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -