Convert Enum To Dictionary .Net

Convert Enum To Dictionary .Net

Added by Sixth Sense updated on Thursday, December 7, 2017


The following code snippet demonstrates how to convert Enum to Dictionary.

public Dictionary DictionaryFromEnum(Type enumType)
	if (!enumType.IsEnum)
    	throw new ArgumentException("Type must be an enum");
    Array values = Enum.GetValues(enumType);
    Dictionary result = new Dictionary(values.Length);
    foreach(var v in values)
    	result.Add((int)v, v.ToString());
	return result;

Related Tags


32 Tutorials
27 Snippets
6 Products


Contact Us

Contact us

Stay Connected