Census data from file input (text) The program takes census data from a text file in the format age, gender, marital status, district. It then gives a list of residents by district (there are 22) and by 5 age groups. Any suggestions for improvement? 

The only topics we have covered so far in class are methods, decisions, looping, and arrays.

static void Main(string[] args)
    {
        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];
        int[] countDist = new int[23];
        int[] ageGroup = new int[5];

        inputRecord = inFile.ReadLine();

        int i = 0;
        while (inputRecord != null)
        {
            fields = inputRecord.Split(',');

            ageData[i] = int.Parse(fields[0]);
            genderData[i] = fields[1];
            maritalData[i] = fields[2];
            districtData[i] = int.Parse(fields[3]);

            if (ageData[i] &gt; 0 &amp;&amp; ageData[i] &lt;= 18)
            {
                ageGroup[0] = ageGroup[0] + 1;
            }
            if (ageData[i] &gt; 18 &amp;&amp; ageData[i] &lt;= 30)
            {
                ageGroup[1] = ageGroup[1] + 1;
            }
            if (ageData[i] &gt; 30 &amp;&amp; ageData[i] &lt;= 45)
            {
                ageGroup[2] = ageGroup[2] + 1;
            }
            if (ageData[i] &gt; 45 &amp;&amp; ageData[i] &lt;= 64)
            {
                ageGroup[3] = ageGroup[3] + 1;
            }
            if (ageData[i] &gt;= 65)
            {
                ageGroup[4] = ageGroup[4] + 1;
            }

            i++;

            inputRecord = inFile.ReadLine();            
        }
        Console.WriteLine("This Program takes census data from a file and lists residents by age group and district");
        Console.WriteLine("Please ensure the file is formatted correctly! age,gender (M/F),marital status   (M/S), and district");
        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");



        Console.WriteLine("------Amount of Residents per Age Group--------");
        Console.WriteLine("Age Group 18 &amp; under = {0}", ageGroup[0]);
        Console.WriteLine("Age Group 18-30 = {0}", ageGroup[1]);
        Console.WriteLine("Age Group 31-45 = {0}", ageGroup[2]);
        Console.WriteLine("Age Group 46-64 = {0}", ageGroup[3]);
        Console.WriteLine("Age Group 65 &amp; over = {0}", ageGroup[4]);
    }


EDIT

Per comments below, the instructor thinks I should get rid of the ageGroup and districtData. This is what he was suggesting I do - however, I have no idea how I'm going to change my logic that was using districtData.

   for (int districtCount = 1; districtCount &lt;= 22; districtCount++)
   {
       for (int districtNumber = 0; districtNumber &lt; districtData.Length; districtNumber++)
       {
           if (districtData[districtNumber] == districtCount)
           {
             countDist[districtCount]++;
           }
       }
   }
user2023861 covers a lot of good ground, so I just have a couple more things to add.

First, instead of using parallel arrays, you might want to consider using a collection container like a List and filling it with objects.  Each line appears to a distinct record with a set of properties, so I would make them a simple Class:

public class Record
{
    public int Age { get; set; }
    public string Gender { get; set; }
    public string MaritalStatus { get; set; }
    public int District { get; set; }
}


That way, you don't have to hard code the size of the arrays that you are using, and you don't have to do any work to keep the related pieces of the record in synch (think what would happen if one of the arrays got sorted and the rest didn't).

Then, in your parser you can create objects for each record:

var records = new List&lt;Record&gt;();
var inputRecord = inFile.ReadLine();

while (inputRecord != null)
{
    var fields = inputRecord.Split(',');
    var currentRecord = new Record()
    {
        Age = int.Parse(fields[0]),
        Gender = fields[1],
        MaritalStatus = fields[2],
        District = int.Parse(fields[3])
    };

    records.Add(currentRecord);
    //...
}


You need to remember to dispose of  your FileStream and StreamReader if you are accessing them this way.  The easier and safer way to do this is with the using syntax, which will close and dispose of them at the ending braces.  I'd get into the habit of using this with any object with a .Dispose() method.

using (var fStream = new FileStream("test.txt", FileMode.Open, FileAccess.Read))
{
    using (var inFile = new StreamReader(fStream))
    {
        //Work with the file here
        //...
    } //inFile.Dispose() happens here automatically.
} //fStream.Dispose() happens here automatically.


This code...

    for (int x = 1; x &lt;= 22; x++)
        for (int y = 0; y &lt; districtData.Length; y++)
            if (districtData[y] == x)
                countDist[x]++;


...is begging for braces to make it easier to read.  It also help avoid potential errors.