public static int NextId(int[] ids)
{
int UniqueElement = 0;
for (int i = 0; i < ids.Length; i++)
{
for (int j = i + 1; j < ids.Length; j++)
{
if (ids[i] == ids[j])
return 0;
if (ids.Any(d => ids[i] + 1 == ids[i + 1]))
{
UniqueElement = ids[i] + 1;
}
else
{
return ids.Max() + 1;
}
}
}
return UniqueElement;
}