Convert value to dynamic data type

May be you have come across the situation that you need to convert some value to dynamically defined data type. But you don’t know the proper way to do it and you end this situation using switch case statements. But if you do it in a proper way than you do not need to use switch case statement and you can convert value to dynamic data type

So as I said, instead of using switch case statements, there is an another way to achieve the same goal using Convert.ChangeType Method as mentioned in below code sample:

Syntax :

Here in above syntax, value is type of System.Object and type is a type of object to return.

Now let’s take a real life example:

For Example, If you want to convert some value to string or int then you will write a code as mentioned below: