I'm looking for a better way to concatenate dictionary keys, this is what I'm doing now :
Dictionary<int, string> myList = new Dictionary<int, string>();
myList.Add(1, "value");
myList.Add(2, "value");
myList.Add(3, "value");
myList.Add(4, "value");
string choices = "";
foreach (int key in myList.Keys)
{
choices += key + " ";
}
choices = "(" + choices.Trim().Replace(" ", ",") + ")"; // (1,2,3,4)
I'm sure there is a better way, with LINQ maybe ?
string.Format("({0})", string.Join(",", myList.Keys));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With