title: C# immutable object setter understanding
body: <p>I have immutable class F1. And i want to change one of it's field. In set method i must return new instance of F1 class with changing. I doesn't understand how i can do this.</p>
  
  <pre><code>public class F1
  {
      public readonly int k1;
      public readonly ImmutableList&lt;int&gt; k2;
  
      public F1(int k)
      {
          ...
      }
  
      public int GetItem(int pos)
      {
          return k2[pos];
      }
  
      public F1 SetItem(int pos, int val)
      {
          return new F1() // How i can create new instance with changes in pos
      }
  }
  </code></pre>
  
  <p>There is Replace method in String.cs. String is immutable class in C# (or i think so). Replace method define like this:</p>
  
  <pre><code>[SecuritySafeCritical]
  [MethodImpl(MethodImplOptions.InternalCall)]
  private string ReplaceInternal(char oldChar, char newChar);
  
  [__DynamicallyInvokable]
  public string Replace(char oldChar, char newChar)
  {
    return this.ReplaceInternal(oldChar, newChar);
  }
  </code></pre>
  
  <p>So i don't know how works ReplaceInternal and then can't find answer for my question.</p>