[Csharp]
<Pre name = "code" class = "csharp"> Primes. cs file </pre>
<Pre> </pre>
<Pre name = "code" class = "csharp"> using System;
Using System. Collections;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication1
{
Public class Primes
{
Private long min;
Private long max;
Public Primes (): this (2,100)
{}
Public Primes (long minimum, long maximum)
{
If (min <2)
Min = 2;
Else
Min = minimum;
Max = maximum;
}
Public IEnumerator GetEnumerator ()
{
For (long possiblePrime = min; possiblePrime <= max; possiblePrime ++)
{
Bool isPrime = true;
For (long possibleFactor = 2; possibleFactor <= (long) Math. Floor (Math. Sqrt (possiblePrime); possibleFactor ++)
{
Long remainderAfterDivision = possiblePrime % possibleFactor;
If (remainderAfterDivision = 0)
{
IsPrime = false;
Break;
}
}
If (isPrime)
{
Yield return possiblePrime;
}
}
}
}
}
</Pre> <pre name = "code" class = "csharp"> <pre name = "code" class = "csharp"> Program. cs file </pre>
<Pre> </pre>
<Pre name = "code" class = "csharp"> using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication1
{
Class Program
{
Static void Main (string [] args)
{
<Span style = "color: # ff0000;"> Primes primesFrom2To1000 = new Primes (2, 10000); // scope defined here </span>
Foreach (long I in primesFrom2To1000)
Console. Write ("{0}", I + "\ t ");
Console. WriteLine ();
Console. ReadKey ();
}
}
}
</Pre> <br>
</Pre>