I can explain the basics,
The index is another file that stores very basic information about your flatfile. In the most simple form, it is a list of PrimaryKeys and there location within the flatfiles.
For instance (using our previous example),
FlatFile
123|Doe|John
567|Doe|Jane
Index
123 0
567 14
What's this mean? Well, the index list the primary key of each Person and their byte location within the flatfile (Don't forget, this is a BYTE count. So if you're writing strings to the file you must also count the NEWLINE and CARRAGE RETURN, +2). So, if you were searching for Person 567 you could search the index file for the primary key 567:
Algorithm:
Open a StreamReader on the index file
Read until you find your primary key for the person (in this case, 567)
Now, open a StreamReader to your FlatFile
Seek to the location (in this case, 14)
Read the information
In this example, the index provides not much increase in speed. You could ask yourself why build this index file when I could just search the FlatFile? Well, imagine your FlatFile holding information similiar (or even more complex) than below:
123|Doe|John|123456 Somewhere Lane|This City|This State|098765-0987|Some Information|Here is some text notes that could go on and on and on and on and on and on and on, I think you get the point. This one record could span a long time.|12/01/01|43|Another note about anything, once again it could go on a long time.
Now, multiply that one record times hundreds, or thousands, of people. You now have a pretty large size file to search through. Your index only holds the neccessary information to get to specific People.
Like I said before, depending on your information your index files could be more complex (perhaps multiple indexes for a single record), or less complex (maybe you don't even need an index). It does put some overhead on the device after the transfer, but it really slices the amount of data to be transfered to the device down nicely.
Hope this helps,
*****************************************
* A copy of the whole thread can be found at:
*
http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-compact-framework/9134
*
* Report spam or abuse by clicking the following URL:
*
http://www.dotnetmonster.com/Uwe/Abuse.aspx?aid=9bc0d169bcaf4d04a16d33ef72da88b7
*****************************************