Prime factoring function using recursion As a programming exercise, I decided to make a prime factoring function using recursion:

    static bool isPrime(int n)
    {
        if (n &lt; 2)
            return false;
        if (n % 2 == 0)
            return (n == 2);
        int root = (int)Math.Sqrt((double)n);
        for (int i = 3; i &lt;= root; i += 2)
            if (n % i == 0) return false;
        return true;
    }

    static bool iseven(int n)
    {
        return n % 2 == 0;
    }

    static int[] prfact(int n, int curr, List&lt;int&gt; nums)
    {
        if (nums.All(x =&gt; isPrime(x)) &amp;&amp; isPrime(curr))
        {
            nums.Add(curr);
            return nums.ToArray();
        }
        else if (iseven(curr))
        {
            nums.Add(2);
            return prfact(n, curr / 2, nums);
        }
        else if (!iseven(curr))
        {
            int div = 3;
            while (curr % div != 0 || !isPrime(div))
                div += 2;

            nums.Add(div);
            return prfact(n, curr / div, nums);
        }
        else
            return null;
    }

    static int[] factor(int n)
    {
        return prfact(n, n, new List&lt;int&gt;());
    }


How efficient is it and how can it be improved?
+1 for stopping your isPrime search at the SqRt(n). That's a nice little optimization. 
+1 for incrementing by 2. It's nice to see you realized that since it wasn't possibly even by this point, that you could optimize. 
Next, consider a sieve or memento implementation for further performance improvements on isPrime. 
Consider renaming root to limit. 
+1 for extracting an isEven method. 
-1 for neglecting to use it in your isPrime method. 
Instead of having prfact and factor, Rename prfact to factor, overloading the latter. Make it private scoped to hide the implementation details from the outside world. 




Sorry for the mostly non-algo review. Not my strong suit &amp; short on time.