using System; class Program { static void Main(string[] args) { int num = 10; bool result = num.GetType().IsAssignableTo(typeof(int)); // returns true Console.WriteLine(result); // output: True } }
using System; class Program { static void Main(string[] args) { string str = "Hello, world!"; bool result = str.GetType().IsAssignableTo(typeof(int)); // returns false Console.WriteLine(result); // output: False } }In this example, we are checking if the type of "str" variable is assignable to the "int" type. Since it is a string and cannot be assigned an integer value, the method returns false. Package library: This method is part of the .NET standard library and can be found in the "System" namespace.