- Convert Value Of String to a type In C#
- String StrType ="Int32"; // Or "Decimal" Or Char Or an Enum Color
- Int32 MyType;
- If (StrType=="Int32")
- Int32 MyType;
- var t = Type.GetType("System.Int32");
- var constructor = t.GetConstructor(Type.EmptyTypes);
- object intObject = constructor.Invoke(null); //intObject will have type System.Int32