1
I need to convert a Dynamic variable to another type in Runtime. The type I want to convert is stored in another variable (I don’t know what type at development time).
There’s something like this?
dynamic dynamicVar = 3;
string tipo = "double";
var valor = MetodoQueConverte(dynamicVar,tipo ) ;
The code above is a summary of what I’m doing. The Methodoconverts() It’s just an example of what I need, it doesn’t have to exist. For example, the variable dynamicVar will stay with type int in this case, but I need to store it somewhere else as double.
I need to do a conversion based on a type that is stored as a string in another variable.
Dude, I couldn’t understand your question or the code presented. Show an example, there’s nothing dynamic and without seeing the
MetodoQueConverte()
you have no idea what you’re trying to do. Try to edit the question by providing a [MCVE]– Leandro Angelo
https://answall.com/q/286192/101
– Maniero
This question should not be closed, because there really is a class in C# that does these types of conversions, it is not
cast
– novic
Bruno be clearer this dynamic type got strange in your question put the value of this dynamicVar!
– novic
I improved the description.
– Bruno Leonardo Conti