Read specific line in text file
问题 Ok so I've got a program that needs to read from a text file that looks like this [Characters] John Alex Ben [Nationality] Australian American South African [Hair Colour] Brown Black Red What I would like to do is only have one method that reads a section depending on the parameter that is passed. Is this possible and how? 回答1: var sectionName = "[Nationality]"; string[] items = File.ReadLines(fileName) //read file lazily .SkipWhile(line => line != sectionName) //search for header .Skip(1) /