object obj = "This is a string"; bool isString = typeof(string).IsAssignableFrom(obj.GetType()); Console.WriteLine(isString); // Output: True
class BaseClass { } class DerivedClass : BaseClass { } bool isAssignable = typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass)); Console.WriteLine(isAssignable); // Output: TrueIn this example, we create two classes, BaseClass and DerivedClass, where DerivedClass inherits from BaseClass. We then use `typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass))` to determine if the DerivedClass is assignable from its base class. The method returns true since DerivedClass is indeed derived from BaseClass. The IsAssignableFrom method is part of the System.Reflection library in C#.