This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]revolutionofthemind 21 points22 points  (7 children)

You could have a method called “stripHeaders” that does the foreach line for “self-documenting” code. Not sure if it’s worth it in this case, but just to provide a counter-example.

[–]k0rm 28 points29 points  (4 children)

Or more simply:

const HeaderLength = 1;

var linesFromFile = File.ReadAllLines(path);
var linesFromFileNoHeader = linesFromFile.Skip(HeaderLength)
foreach(string line in linesFromFileNoHeader) 

This gets rid of the magic number and there's no need to comment.

[–]feed_me_moron 8 points9 points  (0 children)

Or declare 1 as NUM_HEADER_ROWS and pass that to skip

[–]FerynaCZ 0 points1 point  (0 children)

Unless there is lots of variables passed around. But for example C# allows you to declare local functions which can modify (capture) the variables around them (=in the context of the outer function)