using System; class Program { static void Main(string[] args) { int i = 10; Type type = i.GetType(); Console.WriteLine("Type of i is: " + type); Console.ReadLine(); } }
using System; class Animal { } class Dog : Animal { } class Program { static void Main(string[] args) { Animal animal = new Dog(); Type type = animal.GetType(); Console.WriteLine("Type of animal is: " + type); Console.ReadLine(); } }This example code creates an instance of a Dog object and assigns it to an Animal variable. It then uses GetType method to get the type of the Animal variable at runtime. The package library used is System.