I think you need:
Dictionary<eTypeVar, Type> _Types = new Dictionary<eTypeVar, Type> { { eTypeVar.Int, typeof(Int32) }, { eTypeVar.Char, typeof(Char) }, { eTypeVar.Float, typeof(Single) } }; public Boolean Check(eTypeVar type, Object value) { return value.GetType() == _Types[type]; }
You cannot convert a variable to a type for another variable declaration. You need to rethink your design. In any case, it does not do what you do. If you know you want to use int, why not declare it:
String name = "int"; int value = 1;
If you want to have dynamic code for some reason, you can use Reflection and the general method.
public void DoSomething<T>(T value) { .... }
Then you can build the method at runtime using reflection and invoke it. But at this time, I think you need more C # bases to work with these functions.
Felix K.
source share