|
-
May 29th, 2013, 01:24 PM
#4
Re: c# advice - parsing text file
A Dictionary is a hash-table data structure that associates a key with a value. Asking for the key will return the value. Think of it a little like accessing an array, except that you don't have to use integers to index into the array, we can use, for example, string.
It turns out that it is (on average) extremely efficient to retrieve values from a Dictionary based on their key, or - equivalently - to check whether a given key exists in the Dictionary.
A few lines later, we are doing exactly that. Namely, we are checking whether a given string is a key in the table when we call:
Code:
if( targetTable.ContainsKey(line) )
The code snippet you quoted inserts the key (trg, which is one of the lines of ToMatch.txt) and associates it with a value (in this case, zero). Since all we care about here is that the key exists in the Dictionary, and not what the value is, it doesn't matter what value I assigned. I could assign 0. Or 100. Or even a random value for every key.
Make sense?
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|