Is there anyway to handy convert a dictionary to String?

后端 未结 12 1269
死守一世寂寞
死守一世寂寞 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-13 23:55

    You can loop through the Keys of the Dictionary and print them together with the value...

    public string DictToString(Dictionary dict)
    {
        string toString = "";
        foreach (string key in dict.Keys)
        {
                toString += key + "=" + dict[key];
        }
        return toString;
    }
    

提交回复
热议问题