Convert.ChangeType : Convert « System « C# / C Sharp by API






Convert.ChangeType

 
using System;
public class MainClass {
    public static void Main() {

        Type targetType = typeof(int);
        object source = "42";

        object result = Convert.ChangeType(source, targetType);

        Console.WriteLine(result);             // 42
        Console.WriteLine(result.GetType());   // System.Int32
    }
}

   
  








Related examples in the same category

1.Convert.FromBase64CharArray
2.Convert.FromBase64String
3.Convert.ToBase64CharArray
4.Convert.ToBase64String
5.Convert.ToInt32
6.Convert.ToUInt32