反正是有方便的转换字典为String? [英] Is there anyway to handy convert a dictionary to String?

查看:104
本文介绍了反正是有方便的转换字典为String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现的ToString在字典中的默认implemtation是不是我想要的。我想有 {键=值,***}

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?

推荐答案

试试这个扩展方法:

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

这篇关于反正是有方便的转换字典为String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆