As one of the possible solutions (not necessarily the best), you can add your record identifiers to Dictionary<string, int> (or even Dictionary<long, int> if all record identifiers are numeric), where each key is an identifier of one line, and each value is the row index. When you need to find a specific entry, just look in the dictionary (it will be an effective search for you) and give you the line number. If an element is missing (non-existent identifier), you will not find it in the dictionary.
At this point, if the record identifier exists in the file, you have a line number - you can either load the entire file into memory (if it is not too large), or simply search for the desired line and read in the data line.
To do this, you need to go through at least one file and collect all the record identifiers from all the lines and add them to the dictionary. You will not need to perform a binary search - the dictionary will internally perform a search for you.
Edit
If you don’t need all the data from a specific line, just one bit (for example, the location code you specified), you don’t even need to store the line number (since you do not need to return to the line in the file) - just save the location data as a value in dictionary.
I personally would keep the line index, because, in my experience, such projects start small, but ultimately collect functions, and there will be a point where you will need to have everything in the file. If you expect this to happen over time, just analyze the data from each row in the data structure and save it in a dictionary - it will simplify your future life. If you are sure that you no longer need more data than one bit of information, you can simply copy the data into the dictionary.
Here is a simple example (assuming your post IDs can be parsed in long ):
public class LineData { public int LineIndex { get; set; } public string LocationCode { get; set; }
To find out if a record identifier exists, you simply call TryGetValue() :
LineData lineData; if ( _dataMap.TryGetValue ( recordID, out lineData ) ) {
This approach essentially saves the entire file in memory, but all data is analyzed only once (at the beginning, when building the dictionary). If this approach uses too much memory, just save the line index in the dictionary, and then go back to the file if you find the entry and parse the line on the fly.