How to find out if class is derived from another class in C#

1 Answer

0 votes
using System;

public class Base { }
public class Derived : Base { }

class Program
{
    static void Main() {
        Console.WriteLine(typeof(Derived).IsSubclassOf(typeof(Base)));
        Console.WriteLine(typeof(Base).IsSubclassOf(typeof(Base)));
    }
}




/*
run:

True
False

*/

 



answered Aug 23, 2023 by avibootz

Related questions

1 answer 111 views
1 answer 132 views
1 answer 158 views
1 answer 167 views
1 answer 106 views
...