title: C# Array: How do i fill an array with results which get from functions in C#?
body: <p>I try to fill the an array with the result which get from below function.</p>
  
  <p>The function is:</p>
  
  <pre><code>   private int Sum(int i)
     {
          for (int j = 1; j &lt;= i + 1; j++)
          {
              if (i % j == 0)
              {
                  s += j;
              }
          }
          return s;
      }
  </code></pre>
  
  <p>I create an array and then try to use SetValue() or evaluate directly to fill the array with the results.</p>
  
  <p>for example, <code>Array[1]=Sum(1);</code> </p>
  
  <p>However, none of them works. </p>
  
  <p>=====================================================</p>
  
  <p>[Update for more details]</p>
  
  <p>I need use an array with large amount. </p>
  
  <pre><code>int[] arr = new int[10000]
  </code></pre>
  
  <p>I try use below codes</p>
  
  <pre><code>    foreach (int i in arr)
      {
  
          arr.SetValue(Sum(i),i);
      } 
  </code></pre>
  
  <p>And</p>
  
  <pre><code>    for(int i = 0; i&lt;10001; i++)
      {
          arr[i]=Sum(i);
      }
  </code></pre>
  
  <p>None of them works.</p>
  
  <p>======================================================</p>
  
  <p>Is there a way to fill the array with functions?</p>
  
  <p>Sorry for my poor English. :(</p>
  
  <p>Thanks</p>
  
  <p>SuT</p>