title: Sort text file data into an array
body: <p>I'm working on a homework problem for my computer science class. A cities census data is on a text file holding records for its citizens. Each line will have four fields(age, gender, marital status, and district) of different data types separated by a comma. For example, 22, F, M, 1. </p>
  
  <p>How should I approach this? My thoughts are that I should use two 1D arrays, one for age and one for district. I need to be able to later count how many people are in each district, and how many people are in different age groups for the whole city. </p>
  
  <p>How do I read each line and get the info I want into each array? </p>
  
  <p>edit**
  This is what I've managed to do so far. I'm trying to separate my data from fields into four different arrays. This is where I'm stuck.</p>
  
  <pre><code>        FileStream fStream = new FileStream("test.txt", FileMode.Open, FileAccess.Read);
          StreamReader inFile = new StreamReader(fStream);
  
          string inputRecord = "";
          string[] fields;
          int[] ageData = new int[1000];
          string[] genderData = new string[1000];
          string[] maritalData = new string[1000];
          int[] districtData = new int[1000];
  
  
  
          inputRecord = inFile.ReadLine();
          while (inputRecord != null)
          {
              fields = inputRecord.Split(',');
  
              int i = 0;
  
              ageData[i] = int.Parse(fields[0]);
              genderData[i] = fields[1];
              maritalData[i] = fields[2];
              districtData[i] = int.Parse(fields[3]);
              i++;
  
              inputRecord = inFile.ReadLine();
           }
  </code></pre>
  
  <p>edit 2**</p>
  
  <p>First question, I've decided to use the below code to find out how many citizens are in each district of the census data.</p>
  
  <pre><code>for (int x = 1; x &lt;= 22; x++)
              for (int y = 0; y &lt; districtData.Length; y++)
                  if (districtData[y] == x)
                      countDist[x]++;
  
          for (int x = 1; x &lt;= 22; x++)
              Console.WriteLine("District   " + x + "   has   " + countDist[x] + "   citizens");
  </code></pre>
  
  <p>In my <code>.Writeline</code> when <code>x</code> reaches two digits it throws off my columns. How could I line up my columns better?</p>
  
  <p>Second question, I am not quite sure how to go about separating the values I have in <code>ageData</code> into age groups using an if statement.</p>