What is a good way to keep track of strings for dictionary lookups?

Posted by Justin on Programmers See other posts from Programmers or by Justin
Published on 2012-10-06T23:09:21Z Indexed on 2012/10/07 3:51 UTC
Read the original article Hit count: 239

Filed under:
|
|

I am working through the Windows 8 app tutorial.

They have some code about saving app data like so:

 private void NameInput_TextChanged(object sender, TextChangedEventArgs e)
        {
            Windows.Storage.ApplicationDataContainer roamingSettings = 
                Windows.Storage.ApplicationData.Current.RoamingSettings;
            roamingSettings.Values["userName"] = nameInput.Text;
        }

I have worked with C# in the past and found that things like using constant string values (like "userName" in this case) for keys could get messy because auto-complete did not work and it was easy to forget if I had made an entry for a setting before and what it was called. So if I don't touch code for awhile I end up accidentally creating multiple entries for the same value that are named slightly differently.

Surely there is a better way to keep track of the strings that key to those values. What is a good solution to this problem?

© Programmers or respective owner

Related posts about c#

Related posts about dictionary