Created
January 19, 2022 11:16
-
-
Save drikusroor/b9df95e19f02a1278ef29bf04f5e8629 to your computer and use it in GitHub Desktop.
Sort list of lists in dotnet core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text.Json; | |
var array = JsonSerializer.Deserialize<List<List<int>>>("[[3, 2], [1, 1], [0,3],[0,2],[0,1], [1,3], [1,2], [2, 3]]"); | |
Console.WriteLine(JsonSerializer.Serialize(array)); | |
// [[3,2],[1,1],[0,3],[0,2],[0,1],[1,3],[1,2],[2,3]] | |
var sorted = array.OrderBy(y => y[0]).ThenBy(y => y[1]); | |
Console.WriteLine(JsonSerializer.Serialize(sorted)); | |
// [[0,1],[0,2],[0,3],[1,1],[1,2],[1,3],[2,3],[3,2]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment