Possible Duplicate:
Inline functions in C#?
In c++ we can force function inlining.
Is this also possible in c#? sometimes, and when the method is small, it gets inlined automatically. But is it possible force inlining functions in c#/.Net?
Possible Duplicate:
Inline functions in C#?
In c++ we can force function inlining.
Is this also possible in c#? sometimes, and when the method is small, it gets inlined automatically. But is it possible force inlining functions in c#/.Net?
Sort of. It's not under your direct control to turn on for sure. It's never inlined in the IL - it's only done by the JIT.
You can explicitly force a method to not be inlined using MethodImplAttribute
[MethodImpl(MethodImplOptions.NoInlining)]
public void Foo() { ... }
You can also sort of "request" inlining as of .NET 4.5:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Foo() { ... }
... but you can't force it. (Prior to .NET 4.5, that enum value didn't exist. See the .NET 4 documentation, for example.)