My professor gave the class an example of C# that can be used to split data from a text file. I am trying to use it for a project that involves splitting the contents of a txt. file into 4 arrays or fields. Here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
static void Main()
{
int i = 0;
foreach (string line in File.ReadAllLines("census.txt"))
{
string[] parts = line.Split(',');
foreach (string part in parts)
{
Console.WriteLine("{0}",
part);
}
i++;
}
}
}
Here is census.txt:
21,f, s, 14
41,f, m, 22
12, m, s, 12
11, f, s, 8
29, m, m, 4
6, m, s, 12
9, f, s, 2
30, f, s, 1
It's supposed to be hypothetical census data going by age, gender, marital status, and district. The output I keep getting is each of those numbers or chars in a single line like so:
21
f
s
14
41
f
m
22
and so on.
I think it means it's working but I'd like to know how to use this for entering into 4 parallel arrays. I would also to know more about splitting it into 4 fields, structs, or classes. The next part of the project involves counting every time a certain age number or district number appears and that will involve a lot of arrays.
I have no idea what I am doing(managing multiple arrays of data and counting each time a certain data appears from a txt. file) [closed]for context