Taking this code in Java:
protected static <T> T hacerAccion (Class<T> respuesta) {
//implementación...
}
It could be possible to call it this way:
Integer i = hacerAccion(Integer.class);
If what you want is that, what you should do in C # is the following:
protected static T hacerAccion<T> () {
//implementación...
}
Maybe you want Class<T>
to do verifications. In that case, what you want is typeof(T)
:
protected static T hacerAccion<T> () {
if (typeof(T) == typeof(int))
{
// ...
}
//implementación...
}
Unlike Java, in C # you can know the type of data at runtime without having to pass an object that represents it. If you still want an object that represents a type, it would be System.Type
, however there is no System.Type<T>
, use typeof(T)
(which returns System.Type
) instead. Thanks this C # does not need Class<T>
and does not have it.