c# - Sort a Dictionary<Point, int> based on its key -


i have dictionary<point, int> mydic, point class defined below:

public class point {     public double x { get; set; }     public double y { get; set; } } 

how can sort mydic based on key using linq? want order x y.

for example if dictionary below:

key (point (x,y))          value (int) -------------------------------------- (8,9)                      6 (5,4)                      3 (1,4)                      2 (11,14)                    1 

it after sorting:

key (point (x,y))          value (int) -------------------------------------- (1,4)                      2 (5,4)                      3 (8,9)                      6 (11,14)                    1 

orderby , thenby should trick you:

mydic.orderby(x => x.key.x)     .thenby(x => x.key.y)     .todictionary(x => x.key, x => x.value) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -