I found the default implemtation of ToString in the dictionary is not what I want. I would like to have {key=value, ***}.
Any handy way to get it?
How about an extension-method such as:
public static string MyToString
(this IDictionary dictionary)
{
if (dictionary == null)
throw new ArgumentNullException("dictionary");
var items = from kvp in dictionary
select kvp.Key + "=" + kvp.Value;
return "{" + string.Join(",", items) + "}";
}
Example:
var dict = new Dictionary
{
{4, "a"},
{5, "b"}
};
Console.WriteLine(dict.MyToString());
Output:
{4=a,5=b}