Convert String to Type in C# [duplicate]

If I receive a string that contains the name of a class and I want to convert this string to a real type (the one in the string), how can I do this?

I tried

Type.GetType("System.Int32")

for example, it appears to work.

But when I try with my own object, it always returns null …

I have no idea what will be in the string in advance so it’s my only source for converting it to its real type.

Type.GetType("NameSpace.MyClasse");

Any idea?

4 Answers
4

Leave a Comment