Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.35 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Convert Value Of String to a type In C#
  2. String StrType ="Int32"; // Or "Decimal" Or Char Or an Enum Color
  3.        
  4. Int32 MyType;
  5.        
  6. If (StrType=="Int32")
  7.    Int32 MyType;
  8.        
  9. var t = Type.GetType("System.Int32");
  10.     var constructor = t.GetConstructor(Type.EmptyTypes);
  11.     object intObject = constructor.Invoke(null); //intObject will have type System.Int32