c# How do I search by virtual Type variable in parent classes? (inheritance)

Hi guys, I want a way to identify if a class is a type of Enemy by searching the classes it derived, from for example : I have a class named Ship and a class named Astroid both are derived from Enemy, and I want to test if a Ship is a kind of enemy. I can use a virtual Type variable that is later overridden by the subclasses, that is a way to define types to make them easily accessable from outside, but i have no way of searching them yet.

this is my Entity class from wich i want to derive all other classes for example:

using UnityEngine;

public class Entity : MonoBehaviour {

	public virtual string GetType () { return "Entity";  }

}

_
How do I find out if this is a type of Entity in a way that is efficient and usable for searching any class hirarchie ?:

using UnityEngine;

public class Something : Entity{

	public virtual string GetType () { return "Something";  }

}

_
I tried using a virtual list and adding a type to it in each subclass, but virtual doesn’t support lists, so I tried doing it with a string but i realised i don’t know how to make the compiler calculate the string so that it wouldn’t have to be generated every time I create an object in the start method.

The is keyword might be what you want? You also need the right syntax when passing types around.

public void CheckIfEnemy<T>()
{
    return (T is Enemy);
}

You’d use this with:

bool shipIsEnemy  = CheckIfEnemy<Ship>();