Let's say there's a function that generates prime numbers:
static void Main() {
var n = 10;
var primeNumbers = new List<int>();
int current = 2;
// Console.WriteLine(primeNumbers.All((x) => current % x != 0));
while (primeNumbers.Count <= n) {
if (primeNumbers.All((x) => current % x != 0)) {
primeNumbers.Add(current);
Console.WriteLine("Prime number: " + current);
}
current++;
}
}
On the very first iteration within while
the list is empty. Why method Enumerable.All
gives back True
(all elements of a sequence satisfy a condition which is current % x != 0
). What the value of x
?