Passing in an anonymous method/function as a parameter in C# -


i have method needs conditionally execute method, this:

int mymethod(func<int> somefunction) {     if (_someconditionistrue)     {         return somefunction;     }      return 0; } 

i want able pass linq query in mymethod somefunction:

int = mymethod(_respository.where(u => u.id == 1).select(u => u.otherid)); 

how do this?

int = mymethod(() => _respository.where(u => u.id == 1).select(u => u.otherid)); 

as can see, i've made query lambda. have because otherwise, query executed before calling mymethod (...and introduce compile-time errors ;) ) , not while executes.

a side note:

this return somefunction; should return somefunction();.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -