C# Code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace CompareRegistryFiles
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string sDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  14.             string sFilePath = sDesktopPath + "\\" + "3.txt";
  15.             using (StreamReader oStreamReader = new StreamReader(sFilePath))
  16.             {
  17.                 string line;
  18.                 string[] arr = new String[3];
  19.                 int x = 0;
  20.                 while ((line = oStreamReader.ReadLine()) != null)
  21.                 {
  22.                     // 3.txt
  23.                     // a
  24.                     // b
  25.                     // [space]
  26.                     // d
  27.  
  28.                     Console.WriteLine(x + " " + line);
  29.  
  30.                     // if string[] arr = new String[3]
  31.                     // error: Index was outside the bounds of the array.
  32.                     arr[x] = line;
  33.                     x++;
  34.                 }
  35.                 Console.ReadLine();
  36.             }
  37.         }
  38.     }
  39. }

Please see the comments above.
If
if string[] arr = new String[4],
no error.
But there is only 4 lines and the arr index x starts from 0. So the size of arr should be no more than 3.
Could anyone explain to me why the error occurs?
Thanks.