title: Some questions about the usage of MethodImpl Attribute
body: <p>The MSDN reference of the <code>MethodImplOptions</code> are these:</p>
  
  <p><strong><a href="https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions%28v=vs.110%29.aspx" rel="nofollow noreferrer">MethodImplOptions Enumeration</a></strong></p>
  
  <hr>
  
  <p>I would like to learn, firstly, in what circunstances I should use <code>MethodImpl(MethodImplOptions.Unmanaged)</code> and the most important thing, what are the beneffits/optimizations of this (if any)? </p>
  
  <p>I suuposed that I should use it when I do a call to WinAPI function or to a function in a third party C/C++ library, then, this code-example is right?:</p>
  
  <pre><code>&lt;MethodImpl(MethodImplOptions.Unmanaged)&gt;
  Public Shared Sub MyMethod()
  
      ' Call to
      SafeOrUnsafeNativeMethodsClass.RanodmWinAPIFunction()
  
  End Sub
  </code></pre>
  
  <hr>
  
  <p>Secondlly, I would like to learn what value I should use for methods that are declared as shared in a Class, methods that could be call from any part of the code.</p>
  
  <p>An example:</p>
  
  <pre><code>' Sealed class.
  Public NotInheritable Class class1
  
      ' No instanceable class.    
      Private Sub New()
      End Sub
  
      Public Shared Function MyFunc(ByVal parameter1 As String) As Boolean
  
          Return A Boolean Value
  
      End Function
  
  End Class
  </code></pre>
  
  <p>What value of the <code>MethodImplOptions</code> EnumerationI should set for that method in the <code>MethodImpl</code> attribute?.</p>
  
  <p>Here is an user test that demonstrates inlining causes bad performance:</p>
  
  <p><a href="https://softwareengineering.stackexchange.com/questions/245802/is-there-a-downside-to-using-aggressiveinlining-on-simple-properties">https://softwareengineering.stackexchange.com/questions/245802/is-there-a-downside-to-using-aggressiveinlining-on-simple-properties</a></p>
  
  <p>Howhever, I'm not sure if inlining is what I should specify, of if I should set NoOptimization, or what value that will take best performance in the circunstances of shared methods.</p>