Get consecutive integer number ranges from list of int
Your code takes a list, ensures it's sorted and distinct, then assembles and returns another list. This approach is problematic when the input is in fact a generator, in which case your code forces the entire list to memory first. Also, the data might already be sorted or the caller might not be interested in the entire result.

public static List&lt;(int from, int to)&gt; get_consecutive_ranges(List&lt;int&gt; fids)
{
    if (fids == null || fids.Count == 0) return null;

    fids = fids.OrderBy(a =&gt; a).Distinct().ToList();


A much more idiomatic approach is to build an extension method that works on IEnumerable and yields its results. The call to Distinct().OrderBy(a =&gt; a) should be left to the caller. Also note that Distinct doesn't guarantee any particular order, so the sorting must always happen afterwards. The actual logic is overly complicated in your code and be greatly simplified as well. Here is how I would do it:

public static IEnumerable&lt;(int begin, int end)&gt; Ranges(this IEnumerable&lt;int&gt; nums)
{
    var e = nums.GetEnumerator();
    if (e.MoveNext())
    {
        var begin = e.Current;
        var end = begin + 1;
        while (e.MoveNext())
        {
            if (e.Current != end)
            {
                yield return (begin, end);
                begin = end = e.Current;
            }
            end++;
        }
        yield return (begin, end);
    }
}


Add a simple helper function for pretty printing, which should also be an extension method:

public static string Show(this IEnumerable&lt;(int begin, int end)&gt; ranges)
{
    return "[" + string.Join(",", ranges.Select(r =&gt; r.end - r.begin == 1 ? $"{r.begin}" : $"{r.begin}-{r.end-1}")) + "]";
}


Example usage:

Console.WriteLine(new int[] { }.Ranges().Show());                             -&gt; "[]"
Console.WriteLine(new int[] { 1 }.Ranges().Show());                           -&gt; "[1]"
Console.WriteLine(new int[] { 1, 2, 3, 4, 5 }.Ranges().Show());               -&gt; "[1-5]"
Console.WriteLine(new int[] { 1, 2, 3, 5 }.Ranges().Show());                  -&gt; "[1-3,5]"
Console.WriteLine(new int[] { 1, 3, 5, 6 }.Ranges().Show());                  -&gt; "[1,3,5-6]"
Console.WriteLine(new int[] { 1, 3, 3, 3, 5, 6 }.Distinct().Ranges().Show()); -&gt; "[1,3,5-6]"
Console.WriteLine(new int[] { 6, 3, 5, 1 }.OrderBy(i =&gt; i).Ranges().Show());  -&gt; "[1,3,5-6]"