Advertisement
Caminhoneiro

RunTime type convertion

Jul 16th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1.  
  2.     [TestClass]
  3.     public class RuntimeConversionsExample
  4.     {
  5.         [TestMethod]
  6.         public void Example()
  7.         {
  8.             Type targetType;
  9.             Type convertedType;
  10.             object convertedValue;
  11.             object initialValue;
  12.  
  13.  
  14.             initialValue = "99";            
  15.             targetType = typeof (int);
  16.  
  17.             convertedValue = Convert.ChangeType(initialValue, targetType);            
  18.             convertedType = convertedValue.GetType();
  19.  
  20.  
  21.             targetType = typeof (double);
  22.  
  23.             convertedValue = Convert.ChangeType(initialValue, targetType);
  24.             convertedType = convertedValue.GetType();
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement