C# Fake Enum TypeInitializationException

Posted by userk on Stack Overflow See other posts from Stack Overflow or by userk
Published on 2010-05-21T00:12:41Z Indexed on 2010/05/21 0:30 UTC
Read the original article Hit count: 220

Filed under:

I'm trying to create a class that works as a flexible enum. I came with this idea, with 2 additional static methods that allow me to add new members to that list and get only members from that list.

public class LikeEnum
{
         private static List<LikeEnum> list = new List<LikeEnum>()
         { new LikeEnum("One"), new LikeEnum("Two") };

         private string value;

         private LikeEnum(string value)
         {
               this.value = value;
         }
}

Unfortunately the List list is only initialized as null so this doesn't work...

Any ideas or suggestions?

© Stack Overflow or respective owner

Related posts about c#