title: How to pass a constant string reference to function
body: <p>This post is not really about the bug in the code down below, I can myself imagine dozens of ways to solve it, its more principally related to simplicity, elegance and performance!</p>
  
  <p>I had to do a very simple text parser, something like that:</p>
  
  <pre><code>string ParseWord(ref string Line, ref int Pos) {
      // Inspect Line from Pos, increment Pos and return next Word
  }
  
  void ParseText(string[] Lines) {
      foreach (string Line in Lines) {
          int Pos = 0;
          string Word;
          while ((Word = ParseWord(ref Line, ref Pos)) != null) {
              // Do something with Word
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately it does not work that way, because the "foreach" variable "Line" is passed by reference which is not allowed.</p>
  
  <p>As you might have noticed by now I am usually a C++ programmer.
  My thought was that passing the string as reference would be faster, cause it does not have to be copied each time.</p>
  
  <p>First question: Is that assumption still valid in c#?</p>
  
  <p>Second question: How can I pass a reference to that "Line" and still use "foreach" - there is no "const" in c#</p>
  
  <p>Third question: Am I thinking some inappropriate C++ way and something like that would we done different in c#?</p>