I want to check if a generic variable is of a certain type but don’t want to check the generic part.
Let’s say I have a variable of List<int> and another of List<double>. I just want to check if it is of type List<>
if(variable is List) {}
And not
if (variable is List<int> || variable is List<double>) {}
is this possible?
Thanks
Of course, this only works if variable is of type
List<T>, and isn’t a derived class. If you want to check if it’sList<T>or inherited from it, you should traverse the inheritance hierarchy and check the above statement for each base class: