Reading from a file and organizing data in C#

complete

New Member
Joined
Aug 12, 2012
Messages
2
Reaction score
0
There are some cool classes and tricks and short cuts in C#. I know this but I have not worked with C# enough to have them memoried.

One cool trick is this. If you read from a file data that is arranged in a similar line-by-line structure where each line is arranged in columns spaced out by tabs, the data can be read into a kind of class in C# and then you can parse out one column of data by simply doing a "for each" command. Does anyone know off-hand how this is done?
 
There are some cool classes and tricks and short cuts in C#. I know this but I have not worked with C# enough to have them memoried.

One cool trick is this. If you read from a file data that is arranged in a similar line-by-line structure where each line is arranged in columns spaced out by tabs, the data can be read into a kind of class in C# and then you can parse out one column of data by simply doing a "for each" command. Does anyone know off-hand how this is done?

Depends, if you want to just loop through the data once you may wanna try:

Code:
foreach(var line in File.ReadLines("myfile.txt"))...

That should keep your memory usage low. The you can just figure out a way to parse each line, maybe use string's Split() function.
 
Top
Sign up to the MyBroadband newsletter
X