CSharp · Console
using System;
using System.Collections.Generic;
using System.IO;
public class Program
{
public static void Main(string[] args)
{
var foo = new Dictionary<string, string>
{
["now"] = "is",
["the"] = "time",
["for"] = "all",
["good"] = "men",
["to"] = "come",
};
Console.WriteLine(foo.ToCsvFormat());
}
}
public static class DictionaryExtensions
{
public static string ToCsvFormat<TK,TV>(this IDictionary<TK,TV> dict)
{
var sw = new StringWriter();
foreach(var kv in dict)
{
sw.WriteLine($"{kv.Key}, {kv.Value}");
}
return sw.ToString();
}
}