I am new to C#, so need your help.
I have a file that has a lot of lines and 3 tab delimited fields. I want to read each line, extract the fields from the line, and push the 3 extracted values into an object. In the end, I should get an array of objects. The length of the array should be equal to the number of lines in the file. And all the information in the file should get be contained in the objects.
Eg File
abcd pqrs mnop
asdf asdf asdf
poiu poiu poiu
xcvx xcvb rtew
: : : :
: : : :
: : : :
This is what I could come up with:
Class Definition
Class MyClass
{
string field1;
string field2;
string field3;
}
Main
String[] Content = File.ReadAllLines("file.txt");
var query = from line in Content
let Parts = line.Split(Separators,StringSplitOptions.RemoveEmptyEntries)
select new MyClass
{field1 = Parts[0],
field2 = Parts[1],
field3 = Parts[2],
};
How to I get a List or IEnumerable of objects from this?