title: C# streamreader and streamwriter onto same file
body: <p>How do I read and write onto the same file?</p>
  
  <p>A sample of my code looks like this:</p>
  
  <pre><code>List&lt;string&gt; Data = new List&lt;string&gt;();
  
  StreamReader sr = new StreamReader(@"C:\Users\manda\Desktop\Schule\Pos1\HüW2Casino\Spieler1.conf");
  
  StreamWriter sw = new StreamWriter(@"C:\Users\manda\Desktop\Schule\Pos1\HüW2Casino\Spieler1.conf");
  
  while ((line = sr.ReadLine()) != null)
  {
      Data.Add(line);
  }
  
  int budget = int.Parse(Data[1].Substring(15, 3));
  
  for (int i = 0; i &lt; Data.Count; i++)
  {
      if (Data[i] != "ENDE")
      {
          numb = rnd.Next(0, 7);
  
          if (Data[i].Substring(0,1) == "0" || Data[i].Substring(0, 1) == "1" || Data[i].Substring(0, 1) == "2" || Data[i].Substring(0, 1) == "3" || Data[i].Substring(0, 1) == "4" || Data[i].Substring(0, 1) == "5" || Data[i].Substring(0, 1) == "6" || Data[i].Substring(0, 1) == "7")
          {
              betnumb = int.Parse(Data[i].Substring(0, 1));
              betamount = int.Parse(Data[i].Split(' ') [1]);
  
              if (betnumb == numb)
              {
                  budget += betamount * 7;
              }
              else
              {
                  budget -= betamount;
              }
  
              if (budget &lt; 0)
              {
                  sw.Write("Pleite");
                  Console.WriteLine("Pleite");
              }
          }
      }
  }
  </code></pre>
  
  <p>But it seems like I can't read and write onto the same file, as there are no changes to the file, never.</p>
  
  <p>Maybe anyone knows what my problem is?</p>