I need to re-order a list consecutively if it is already not. Can anyone suggest a way to check it so that I can write an extension method to call like this?
var cglist = collectionGroups.OrderBy(x => x.Sequence).ToList();
if (cglist.IsConsecutive)
{
for (int i = 0; i < cglist.Count(); i++)
{
//sorting logic...
}
}
x.Sequence
is not an incremented property in the entity and has duplicates and missing values. This data is fed to my context from an outer source which I have no control of. So I need to use it in a reordering method and make it adjacent
I could find the closest solution from this answer here which does not really seem to be checking adjacency.