title: Converting VB code to C# using array and redim preserver keyword
body: <p><strong>This is my VB code:</strong></p>
  
  <pre><code>If TxtStr(i) = "#" And TxtStr(i + 1) = "]" Then
      RefStr = RefStr &amp; "]"
      ReDim Preserve RefStrLinks(1, RefStrLinkIndex)
      RefStrLinks(0, RefStrLinkIndex) = RefStr
      RefStr = RefStr.Replace("[#", String.Empty)
      RefStr = RefStr.Replace("#]", String.Empty)
      RefStrLinks(1, RefStrLinkIndex) = RefStr
      RefStrLinkIndex = RefStrLinkIndex + 1
      RefStr = String.Empty
      RefStrFound = False
  End If
  </code></pre>
  
  <p><strong>This is my converted code in C#;</strong> <code>RefStrLinks</code> is declared as:</p>
  
  <pre><code>string[,] RefStrLinks = null;
  </code></pre>
  
  <p>But this gives a compile error because of <code>ReDim Preserve</code> whenever I run this:</p>
  
  <pre><code>if (TxtStr[i].ToString() == "#" &amp; TxtStr[i + 1].ToString() == "]")
  {
      RefStr = RefStr + "]";
      Array.Resize&lt;string&gt;(ref RefStrLinks, RefStrLinkIndex + 1);
      RefStrLinks[0, RefStrLinkIndex] = RefStr;
      RefStr = RefStr.Replace("[#", string.Empty);
      RefStr = RefStr.Replace("#]", string.Empty);
      RefStrLinks(1, RefStrLinkIndex) = RefStr;
      RefStrLinkIndex = RefStrLinkIndex + 1;
      RefStr = string.Empty;
      RefStrFound = false;
  }
  </code></pre>
  
  <p>Does anybody understand why?</p>