Convert variable data type based on other variable data type

How to convert certain variable’s data type based on other variable’s data type.

  1. test1 - System.String
  2. test2 - System.Double

Scenario is we don’t know the data type of test2 in the first place. Goal - convert test1’s’ data type the same as test2’s data type.


If you want to know what type of variable it is then try below one.


Object.GetType Method (System) | Microsoft Learn

Thanks. But how can i use the result of this to convert certain variable?

1 Like


Please check below thread.

c# - Cast a variable to a type represented by another Type variable? - Stack Overflow