ok, this should be interesting.
lets assume i have the following code:
in this example, the first available number would be 2.
List<long> myList = new List<long>(){0,1,10,3};
in this example, the first available number would be ‘4’.
List<long> myList = new List<long>(){0,1,2,3};
any ideas?
So by “available” you mean “the lowest non-negative number which doesn’t already exist in the list”?
I’d be tempted to write something like:
EDIT: Alternatively, you could order the list and then find the first value where the index isn’t the same as the value…
The last line is to take care of the situation where the list is contiguous from 0. Another alternative would be:
This should be fine so long as the list doesn’t contain
long.MaxValue + 1elements, which it can’t in current versions of .NET. (That’s a lot of memory…) To be honest, this will already have problems when it goes beyondint.MaxValueelements due to theSelectpart taking anintindex…