Facebook
From Putrid Shama, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 222
  1. public class Program
  2. {
  3.         public static void Main()
  4.         {
  5.                 foreach(int primeNumber in GetPrimeNumbers().Take(100))
  6.                 {
  7.                         Console.WriteLine(primeNumber);
  8.                 }
  9.         }
  10.  
  11.         public static IEnumerable<int> GetPrimeNumbers()
  12.         {
  13.                 List<int> processedPrimes = new List<int>();
  14.                 for(int value = 2;; value++)
  15.                 {
  16.                         if (!processedPrimes.Any(n => value % n == 0))
  17.                         {
  18.                                 processedPrimes.Add(value);
  19.                                 yield return value;
  20.                         }
  21.                 }
  22.         }
  23. }