AddressInfo Update

0 comments suggest edit

A long time ago, in a galaxy far away, I wrote a really simple little class for converting State Codes to State Names and Vice Versa.

Essentially, this class contained two enums, one for state codes such as AK and CA. Another enum contained state names such as Alaska and California. There were static methods that facilitated converting between the the two as well as string representations.

Simple stuff really, but very helpful if you deal with states all the time. However, just today I received an email from Omer pointing out that I am trusting the order of the two enums values to be aligned to allow conversions between the two. While it happens to work, it creates a dependency on the order of the values that doesn’t need to be there. You never know when we’ll annex Iraq as our 51st state and need to add a value to the enums.

In any case, I took Omar’s Omer’s suggestion to have one of the enums refer to the other. For example, here’s a snippet of the StateCode enum.

public enum StateCode


    /// <summary>Alabama</summary>

    AL = State.Alabama,

    /// <summary>Alaska</summary>

    AK = State.Alaska,

    ///… and so on


Download the revised code here. Thanks Omer!

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



7 responses

  1. Avatar for Omer van Kloeten
    Omer van Kloeten August 6th, 2005

    Funny enough, you write my name three times, and spell it correctly twice.

    Could be a deep trauma in your childhood. Would you like to talk about it? :)

  2. Avatar for Haacked
    Haacked August 6th, 2005

    Ahh! Damn It! I blame Jet Lag! In fact, I will henceforth blame Jet Lag for all my mistakes. Sorry about that, the error has been corrected, with the original mistake struck through for posterity and as a warning to others.


  3. Avatar for Omer van Kloeten
    Omer van Kloeten August 6th, 2005

    ...and the world rejoices with us :)

  4. Avatar for user
    user August 6th, 2005

    I've been searching for similar piece of code. But there are no any licence in . Can I use it free ?

  5. Avatar for Haacked
    Haacked August 6th, 2005

    Unless I include a specific copyright notice in code posted to my site, it has the same license as my blog (see the link at the bottom).

    Basically, you can use it, modify it, etc... Just attribute me. Thanks!

  6. Avatar for Another Challenge for you: Cou
    Another Challenge for you: Cou August 8th, 2005


    Since you've done this for states, I have a new challenge for you: try writing a similar code for 2 and 3 character country ISO codes. I don't think you could really sell it, but I know anyone who works in international corporations would be extremely thankful. If that's too easy for you, try writing code to convert international currency codes into the full currency name. An example, ZAR is South African Rand.

  7. Avatar for Haacked
    Haacked August 8th, 2005

    Interesting. Maybe when I have a personal need I can try it. But for now, I have too much other work to do. Thanks for the challenge though.