For loop to calculate factorials
A little late to the party:
Func<int, int> factorial = n => n == 0 ? 1 :
Enumerable.Range(1, n).Aggregate((acc, x) => acc * x);
int numberInt = int.Parse(factorialNumberTextBox.Text);
int result = numberInt;
for (int i = 1; i < numberInt; i++)
{
result = result * i;
}
factorialAnswerTextBox.Text = result.ToString();
on a side note: this would normally NOT be the correct way to calculate factorials. You'll need a check on the input before you can begin calculation, in case your starting value is 1 or below, in that case you need to manually return 1.
On another side note: this is also a perfect example of where recursive methods can be useful.
int Factorial(int i)
{
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}