title: __makeref as a way to get a reference value in C#?
body: <p>I've seen this code which was used showing the reference value : </p>
  
  <pre><code>static void Main(string[] args)
  {
      string s1 = "ab";
      string s2 = "a"+"b";
      string s3 = new StringBuilder("a").Append("b").ToString();
  
      Console.WriteLine(GetMemoryAddress(s1));
      Console.WriteLine(GetMemoryAddress(s2));
      Console.WriteLine(GetMemoryAddress(s3));
  }
  
  static IntPtr GetMemoryAddress(object s1)
  {
      unsafe
      {
          TypedReference tr = __makeref(s1);
          IntPtr ptr = **(IntPtr**) (&amp;tr);
          return ptr;
      }
  }
  </code></pre>
  
  <p>Result (as expected): </p>
  
  <p><a href="https://i.stack.imgur.com/EzbOb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EzbOb.png" alt="enter image description here"></a></p>
  
  <p><em>(I know that string interning kicks in here, but that's not the question).</em></p>
  
  <p><strong>Question:</strong></p>
  
  <p>Although it seems that it does do the job, 
  Does using <code>__makeref</code> is this the right way of getting the reference value in c#?</p>
  
  <p>Or are there any situations in which this ^ would fail ....?</p>