title: How can you count the occurrence of 1 from 1 to 99,999,999 (1 short of 100 million) and total up how many 1s were there
body: <p>i started learn c# and in such task. i have already do it this is the code:</p>
  
  <pre><code>string y = "";
  int count = 0;
  string x  = "";
  string[] arr = new string[100000000];
  
  for (int i = 0; i &lt; 100000000; i++)
  { 
      x = i.ToString() + x;
  }
  
  Console.WriteLine(x);
  
  for (int j = 0; j &lt; x.Length; j++)
  {
      y = x.Substring(j, 1);
  
      switch (y)
      {
          case "1":
               count ++;
               break;
  
          default:
              break;
      } 
  }
  
  Console.WriteLine(count);
  </code></pre>
  
  <p>The code worked correctly in case of small range (0 to 1000) but when running it for a range of 100 million it does not produce any result (i waited for while but no output)plus it looks like my code is not efficient way. my question now is what is the problem in this code and if there was a better solution for this task.</p>