I want to create an extension method like this
public static bool AllConsecutives(this IEnumerable<int> intValues )
This method should return true if all items in the list are consecutive (with no gaps)
some test cases
(new List<int>() {2, 3, 4, 5, 6}).AllConsecutives() == true
(new List<int>() {3, 7, 4, 5, 6}).AllConsecutives() == true //as it is not sensitive to list order
(new List<int>() {2, 3, 4, 7, 6}).AllConsecutives() == false //as the five is missing
You can also verify, that collection has at least one item, before executing
Min. Or you can sort items prior to taking min (in this case it will be first one, or will not be any, if collection is empty). Also in this case you will save one iteration for finding minimal value: