I have started to use anonymous delegates a lot in C# and I have begun to wonder how efficient the complier or runtime is in removing them from the code that is actually run and I haven’t seen this detailed anywhere?
Is it clever enough at all to inline them and collapse recursive uses that could be statically deduced?
No the C# compiler will not optimize a lambda expression into inline code. Anonymous delegates and lambda expressions will always produce a corresponding delegate or an expression tree. This is covered in section 6.5 of the C# language spec
In certain cases the lambda will be cached and not recreated for future use. But it will not be inlined.