Is there anyway to handy convert a dictionary to String?

后端 未结 12 1253
死守一世寂寞
死守一世寂寞 2020-12-13 23:50

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?

12条回答
  •  感动是毒
    2020-12-14 00:00

    Try this extension method:

    public static string ToDebugString (this IDictionary dictionary)
    {
        return "{" + string.Join(",", dictionary.Select(kv => kv.Key + "=" + kv.Value).ToArray()) + "}";
    }
    

提交回复
热议问题