Mega Code Archive

 
Categories / C# / Data Types
 

Returns an object of the specified type and whose value is equivalent to the specified object

using System; public class ChangeTypeTest {     public static void Main() {         Double d = -2.3;         int i = (int)Convert.ChangeType(d, typeof(int));         Console.WriteLine("The double value {0} when converted to an int becomes {1}", d, i);         string s = "12/12/99";         DateTime dt = (DateTime)Convert.ChangeType(s, typeof(DateTime));         Console.WriteLine("The string value {0} when converted to a Date becomes {1}", s, dt);             } }