AddressInfo Update

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!

What others have said

Requesting Gravatar... Omer van Kloeten Aug 06, 2005 11:15 AM
# re: AddressInfo Update
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? :)
Requesting Gravatar... Haacked Aug 06, 2005 12:34 PM
# re: AddressInfo Update
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.
;)
Requesting Gravatar... Omer van Kloeten Aug 06, 2005 1:52 PM
# re: AddressInfo Update
...and the world rejoices with us :)
Requesting Gravatar... user Aug 06, 2005 11:47 PM
# re: AddressInfo Update
I've been searching for similar piece of code. But there are no any licence in AddressInfo.zip . Can I use it free ?
Requesting Gravatar... Haacked Aug 07, 2005 1:05 AM
# re: AddressInfo Update
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!
# re: AddressInfo Update
Phil,

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.
Requesting Gravatar... Haacked Aug 09, 2005 7:48 AM
# re: AddressInfo Update
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.

What do you have to say?

(will show your gravatar)
Please add 7 and 8 and type the answer here: