Is there anyway to handy convert a dictionary to String?

后端 未结 12 1231
死守一世寂寞
死守一世寂寞 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:15

    Another solution:

    var dic = new Dictionary()
    {
        {"A", 100.0 },
        {"B", 200.0 },
        {"C", 50.0 }
    };
    
    string text = dic.Select(kvp => kvp.ToString()).Aggregate((a, b) => a + ", " + b);
    

    Value of text: [A, 100], [B, 200], [C, 50]

提交回复
热议问题