c# - Concatenate dictionary keys separated by comma's -
i'm looking better way concatenate dictionary keys, i'm doing :
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 better way, linq maybe ?
string.format("({0})", string.join(",", mylist.keys));
Comments
Post a Comment