Created
April 30, 2024 10:49
-
-
Save gauravkhuraana/b21b8949d1c62a6308dbbb299dc28641 to your computer and use it in GitHub Desktop.
To check if dates in a list of json are sorted or not
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
{ | |
"Date": "2022-04-01T00:00:00Z", | |
"Number": 1 | |
}, | |
{ | |
"Date": "2022-04-01T00:00:00Z", | |
"Number": 1 | |
}, | |
List<AllDataFromJson> AllDataFromJson = JsonConvert.DeserializeObject<List<MyObject>>(json); | |
bool datesInAscendingOrder = AllDataFromJson.Select(o => o.Date).SequenceEqual(AllDataFromJson.Select(o => o.Date).OrderBy(d => d)); | |
datesInAscendingOrder.Should().BeTrue(); | |
bool datesInDescendingOrder = AllDataFromJson.Select(o => o.Date).SequenceEqual(AllDataFromJson.Select(o => o.Date).OrderByDescending(d => d)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment