How to force inline functions in C#? [duplicate]

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.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)