System.Collections.Generic.HashPrimeNumbers.TestPrime C# (CSharp) Method

TestPrime() public static method

public static TestPrime ( int x ) : bool
x int
return bool
        public static bool TestPrime(int x)
        {
            if ((x & 1) != 0)
            {
                int top = (int)Math.Sqrt(x);

                for (int n = 3; n < top; n += 2)
                {
                    if ((x % n) == 0)
                        return false;
                }
                return true;
            }
            // There is only one even prime - 2.
            return (x == 2);
        }