Here's an alternative. This one uses the BitArray
class in C# and does not use the %
operator.
static List<int> SeiveWithoutMod(int candidate)
{
BitArray sieveContainer = new BitArray(candidate + 1, true);
int marker = 2;
int factor = 2;
sieveContainer[0] = false;
sieveContainer[1] = false;
while ((marker * marker) <= sieveContainer.Length)
{
while ((factor += marker) <= candidate)
{
sieveContainer[factor] = false;
};
factor = ++marker;
}
return GetPrimes(sieveContainer);
}