title: c# how to save dictionary to a text file
body: <p>I am trying to save dictionary in txt file and I am looking for simple examples.Can you help me,please? I am trying this but it does not work for me.Thanks.</p>
  
  <pre><code>Dictionary&lt;string, int&gt; set_names = new Dictionary&lt;string, int&gt;();
          //fill dictionary 
          //then do:
          StringBuilder sb =new StringBuilder();
          foreach (KeyValuePair&lt;string, int&gt; kvp in set_names)
          {
              sb.AppendLine(string.Format("{0};{1}", kvp.Key, kvp.Value));
          }
  
          string filePath = @"C:\myfile.txt";
          using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
          {
              using (TextWriter tw = new StreamWriter(fs))
  </code></pre>