Interesting (and fast) way to fill the gap between numbers:
static void Main(string[] args)
{
int[] gapNumbers = new int[] { 1, 3, 4, 7, 8, 10 };
foreach (int number in FillTheGap(gapNumbers))
{
Console.WriteLine(number);
}
Console.ReadKey();
}
private static IEnumerable<int> FillTheGap(int[] gapNumbers)
{
int prevNumber = 1;
foreach (int number in gapNumbers)
{
if (prevNumber == number)
{
yield return number;
}
else
{
for (; prevNumber < number; prevNumber++)
{
yield return prevNumber;
}
yield return number;
}
prevNumber++;
}
}
POI:
foreach (int number in FillTheGap(gapNumbers))