Finding largest prime factor from inputted number This is my first C# console application. This program asks for an input of a number, and finds the highest prime factor of that number. Please review my code. 


Have I used things right? 
Is my code efficient? 
Is there a better way to achieve this?




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problems
{
    class Program
    {
        static int FindFactor(Int64 UserInput)
        {
            int LargestFactor = 0;
            Int64 Number = UserInput;

            for (int i = 2; i &lt; Number; i++)
            {
                if (Number % i == 0)
                { 
                    if (PrimeFactorCheck(i) == true)
                    {
                        LargestFactor = i;
                    }
                }
            }
            return LargestFactor;
        }
        static bool PrimeFactorCheck(int Number)
        {
            bool PrimeNumberValidity = true;

            for(int i = 2; i &lt; Number; i++)
            {
                if (PrimeNumberValidity == true)
                {
                    if (Number % i == 0)
                    {
                        PrimeNumberValidity = false;
                    }
                }
                else
                {
                    i = Number;
                }
            }

            return PrimeNumberValidity;
        }
        static void Main(string[] args)
        {
            Console.Write("Hello, please enter a number to find the biggest prime factor of it: ");
             Int64 UserInput = Convert.ToInt64(Console.ReadLine());

            int Answer = FindFactor(UserInput);
            Console.WriteLine(Answer);
            Console.ReadKey();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Problems
{


You can make this class static since it doesn't make sense to make instances of it.

    static class Program
    {


Local variables are usually not capitalized.

        static int FindFactor(Int64 userInput)
        {


The compiler can infer the type if you use var, so you won't have to repeat it.

            var largestFactor = 0L;
            var number = userInput;

            for (var i = 2; i &lt; number; ++i)
            {


Use &amp;&amp; instead of nested if-statements.

                if (number % i == 0 &amp;&amp; IsPrimeFactor(i))
                {
                    largestFactor = i;
                }
            }

            return largestFactor;
        }


Usually you put a blank line between function definitions.

Functions returning Booleans are often called "IsBlaBla" instead of "BlaBlaCheck."

        static bool IsPrimeFactor(int number)
        {
            var primeNumberValidity = true;

            for(int i = 2; i &lt; number; ++i)
            {
                if (primeNumberValidity &amp;&amp; number % i == 0)
                {
                    primeNumberValidity = false;


You can exit the loop here because continuing is useless.

                    break;
                }
                else
                {
                    i = number;
                }
            }

            return primeNumberValidity;
        }


args is not used, so you can omit it.

        static void Main()
        {
            Console.Write("Hello, please enter a number to find the biggest prime factor of it: ");

            var userInput = Convert.ToInt64(Console.ReadLine());

            var answer = FindFactor(userInput);
            Console.WriteLine(answer);
            Console.ReadKey();
        }
    }
}




You can use LINQ to implement FindFactor in a functional fashion, rather than imperatively.

static int FindFactor(Int64 number) {
    return IEnumerable.Range(2, number - 2)
                      .Where(n =&gt; number % n == 0 &amp;&amp; IsPrimeFactor(n))
                      .DefaultIfEmpty(0)
                      .Last();
}