consider this code:
Does the compiler emit code to create a new action when the function is called or only when f() is actually called?Code:private void DoIf(bool b, Action f) { if (b) f(); } int x = 0; bool no = false; DoIf(no, () => x = 10);
consider this code:
Does the compiler emit code to create a new action when the function is called or only when f() is actually called?Code:private void DoIf(bool b, Action f) { if (b) f(); } int x = 0; bool no = false; DoIf(no, () => x = 10);
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.
If you understand what you're doing, you're not learning anything.
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.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.