-
Action object
consider this code:
Code:
private void DoIf(bool b, Action f)
{
if (b)
f();
}
int x = 0;
bool no = false;
DoIf(no, () => x = 10);
Does the compiler emit code to create a new action when the function is called or only when f() is actually called?
-
Are you asking about the CLR or the compiler? The compiler is going to do its thing independently of any runtime constraints such as branching.
-
The Action object is syntactic sugar for a delegate taking one argument and returning void. The CLR will defined the object as a sealed class deriving from System.MulticastDelegate and define three public member functions; Invoke, BeginIvoke and EndInvoke. The CIL will call these member functions whenever you use the object.