I
I
iRumba2015-08-18 13:16:28
.NET
iRumba, 2015-08-18 13:16:28

How to convert string str to type type?

Hello. There is a method
void Method(Type type, string str)
{
object o = (type)str;
}
I think it's clear from the line what I want to get. If not, I want to get a variable of type type by converting the string str to that type, if possible.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Lastochkin, 2015-08-18
@iRumba

object o = Convert.ChangeType(str, type);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question