title: Loading data into a 2D array from text file?
body: <p>I am using C# in a console application.</p>
  
  <p>I need to load data from a text file and load it into a 2d array.</p>
  
  <p>This is what I tried, but when I try to print out the contents of what gets returned nothing gets printed.</p>
  
  <pre><code>public static int[,] LoadMap()
  {
      const string path = @"1.txt";
  
      string[] fileLines = File.ReadAllLines(path);
      int[,] map = new int[fileLines.Length, 15];
      string line;
      for (int i = 0; i &lt; fileLines.Length; ++i)
      {
          line = fileLines[i];
          for (int j = 0; j &lt; line.Length; ++j)
          {
              map[i, j] = (int)(line[j] - '0');
          }
      }
  
      return map;
  }
  </code></pre>
  
  <p>But when I hardcode the data like that, then everything gets displayed perfectly.</p>
  
  <pre><code>private static int[,] Map = new int[MapX, MapY]
  {
              { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
              { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
              { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  };
  </code></pre>
  
  <p>The data in the text file looks like that :</p>
  
  <pre><code>0,0,0,1,1,1,1,1,1,1,1,1,1,1,1
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
  </code></pre>
  
  <p>Any help will be appreciated whether you fix what I tried or propose something completely different, thanks.</p>