title: Enumerable.Range.Aggregate Method deal with long integer type
body: <p>I want to solve the <a href="http://projecteuler.net/problem=20" rel="nofollow">Project Euler problem 20.</a></p>
  
  <pre><code>n! means n × (n − 1) × ... × 3 × 2 × 1
  
  For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
  and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
  
  Find the sum of the digits in the number 100!
  </code></pre>
  
  <p>My code is returning a wrong result because it can't deal with long integer type.</p>
  
  <pre><code>        BigInteger x = Enumerable.Range(1, 100).Aggregate((total, next) =&gt; total * next);
          int[] y = Array.ConvertAll(x.ToString().ToArray(), a =&gt; (int)a);
          Console.WriteLine(y.Sum());
  </code></pre>
  
  <p>As at some step the variable </p>
  
  <blockquote>
    <p>total</p>
  </blockquote>
  
  <p>became very big then it was not int type.</p>
  
  <p>I wrote an extension for Range but had difficult time for Aggregate method. My whole code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Numerics;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace p20
  {
      class Program
      {
          // Find the sum of the digits in the number 100!
          static void Main(string[] args)
          {
              DigitsSum();
          }
  
          private static void DigitsSum()
          {
              BigInteger x = ExtentionLong.Range(1, 100).Aggregate((total, next) =&gt; total * next);
              int[] y = Array.ConvertAll(x.ToString().ToArray(), a =&gt; (int)a);
              Console.WriteLine(y.Sum());
              Console.Read();
          }
      }
      public static class ExtentionLong
      {
          public static IEnumerable&lt;long&gt; Range(this long source, long length)
          {
              for (long i = source; i &lt; length; i++)
              {
                  yield return i;
              }
          }
      }
  }
  </code></pre>