In general it does not make much sense you want to know the type of a class, after all the type of this class is the class itself. At least it makes no sense to get this in the example shown. That is, the class type ClasseA
is ClasseA
. It’s obvious in the code.
If you’re in a situation where it’s not so obvious, using reflection, for example, has some alternatives.
Can be using the operator typeof
which is solved at compilation time:
Type t = typeof(Ns.Classe);
You can use the method GetType()
type without creating an instance. Just be careful to use the full name of the type with the namespace
(solved at runtime):
Type t = Type.GetType("Ns.Classe");
I put in the Github for future reference.