Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use generic classes without type parameters? [duplicate]

If I have a templated(generic) class MyClass<T>, is it possible to do something like:

var b = someObject is MyClass; // without specifying <T>
like image 760
John Smith Avatar asked Dec 30 '25 04:12

John Smith


1 Answers

No it's not, but you can use reflection to check the type:

someObject.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(MyClass<>))
like image 83
Selman Genç Avatar answered Jan 01 '26 16:01

Selman Genç