What's the most efficient way to convert a Dictionary to a formatted string.
e.g.:
My method:
public string DictToString(Dictionary<string, string> items, string format){
format = String.IsNullOrEmpty(format) ? "{0}='{1}' " : format;
string itemString = "";
foreach(var item in items){
itemString = itemString + String.Format(format,item.Key,item.Value);
}
return itemString;
}
Is there a better/more concise/more efficient way?
Note: the Dictionary will have at most 10 items and I'm not committed to using it if another similar "key-value pair" object type exists
Also, since I'm returning strings anyhow, what would a generic version look like?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…