How to write the content of a dictionary to a text file?

Posted by codemonkie on Stack Overflow See other posts from Stack Overflow or by codemonkie
Published on 2010-06-18T04:57:03Z Indexed on 2010/06/18 5:03 UTC
Read the original article Hit count: 387

Filed under:
|
|

I have a dictionary object of type Dictionary

and trying to use StreamWriter to output the entire content to a text file but failed to find the correct method from the Dictionary class.

using (StreamWriter sw = new StreamWriter("myfile.txt"))
        {
            sw.WriteLine(dictionary.First());

        }

I can only retrieve the first element and it is bounded by a square bracket plus a comma separator in between as well:

[Peter, Admin]

and would be nice to have [Peter Admin] (without the comma)

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ