c# - Sort Dictionary by key then add all values to list -


i sort dictionary keys take values dictionary , put them array.

for instance,

dictionary<int, string> customernamesbyids = new dictionary<int, string>(); customernamesbyids.add(9, "joe"); customernamesbyids.add(2, "bob");  //sort customernamesbyids int //take sorted dictionary , put them array list<string> customernames; //customernames[0] == "bob"; //customernames[1] == "joe"; 

there seems there should simple way this, have absolutely no idea how. time!!

list<string> customernames = (from c in customernamesbyids                                orderby c.key                                select c.value).tolist(); 

Comments