I have the following code to get the prime numbers between a range of numbers. Is this the best and fastest method?
int[] numberCollection = Enumerable.Range(startNum,Count).ToArray<int>();
string primeNumbers = string.Join(",", from number in numberCollection
where (IsPrime(number)==true)
select number);
Where :
startNum
is the starting numberCount
is the number of numbers in the collectionIsPrime
is a method defined as follows:private static bool IsPrime(int number) { for (int i = 2; i < number/2; i++) if (number % i == 0) return false; return true; }