Ad
  • Custom User Avatar

    "In the solution which everyone is marking as best practice, there is a conversion to (int). Once you use Range and Except you are dealing with INTs at that point. Is (int) conversion really necessary? Just discussing :)"

    No, conversion is not at all neccessary. Also, if you peek at the definition in the System.Linq namespace:

    public static IEnumerable<int> Range(int start, int count);

    There is no IEnumerable<double> Range etc... so there is no confusion.

    .......

    On another note: I notice a lot of folks using FirstOrDefault() and in the case that the Except returns an empty enumerable, 0 would be returned. This would be the incorrect answer. First() throws an InvalidOperationException, but it's not misleading like 0.