Reputation: 53
I am trying to store a Enum class Type as value in Dictionary but i am getting 'Test' is a type, which is not valid in the given context. basically Test is Enum Class.
public enum Test
{
Test1 = 1,
Test2 = 2,
}
and Dictionary:-
private Dictionary<int, Type> _typeMapping;
Upvotes: 0
Views: 93
Reputation: 5203
Solution:
class Program
{
private static Dictionary<int, Type> TypeMapping { get; set; }
static void Main(string[] args)
{
TypeMapping = new Dictionary<int, Type>();
Test test1 = Test.Test1;
TypeMapping.Add((int)test1, test1.GetType());
}
}
public enum Test
{
Test1 = 1,
Test2 = 2
}
Upvotes: 0
Reputation: 4679
I would guess you are doing something like this:
_typeMapping.Add(1, Test);
When you should do this:
_typeMapping.Add(1, typeof(Test));
Upvotes: 1