I have to admit that I have been an enum junkie. I know some people are cringing right now and others are saying "so what?". So let me explain

An enum is a string representation that gets converted to an integer. The only reason for an enum is so that as coders we dont have to remember that a flag of 1=payment, 2=refund, and 3=void. So it allows us to use magic numbers... without using magic numbers.

There are a lot of drawbacks to this method though. For instance, how do you show a string representation of the enum (yes you can use lineEnum.Payment.ToString() but what if you want it to display in multiple different ways?). Also someone can pass in any integer into a method like so:

public enum lineEnum
       Payment=1
       Refund=2
       Void=3
end enum

public sub CreateLine(linetpye as lineEnum)
        ......
end sub

public sub DoStuff()
      CreateLine(32084926439783968396839683)
end sub

now I dont think that is a valid choice but because its an enum (and hence just an integer) no error will be thrown.

My big issue with an application I am working on right now are enum mismatches. This happens when we change the numbering. For example we decide to start at 0 instead of 1 for our enums.

public enum lineEnum
       Payment=0
       Refund=1
       Void=2
end enum

Now any code with a reference to the old assembly containing the enum when they call CreateLine and pass the enum we will have interesting results. Consumers that create a payment will actually create a refund (as payment has been moved to have a value of 0). My recomendation is to not renumber your enum and it very rarely happens (my real recomendation comes later).

Along the same lines as this is that you dont have to use the right enum to do an assigment. The best case of this is in the data namespace. If I set IDbDataParameter.DbType = DbType.Int everything is good but nothing stops me from doing this IDbDataParameter.DbType = SqlDbType.Int.

So enums are not explandable (you can not add any functionality to them), usually lead to nasty switch/select stements, can easily be mismatched, they can take invalid values, and there is no way to only take a certain enum type.

The solution I have been using quite effectively has been to use a strategy pattern to replace my enums. I am not going to write how to do it as Jonas (another edmonton blogger) has this great article on this topic that I recommend you read.