Covert to typeB from typeA

  • Thread starter Thread starter Javier Ros
  • Start date Start date
J

Javier Ros

hi guys,

someone know if exists a function that convert a object from any type to
other type?

exaple:
ConvertFromTO(object obj, System.Type typeSrc, System.Type typeDst);
 
Javier Ros said:
someone know if exists a function that convert a object from any type to
other type?

exaple:
ConvertFromTO(object obj, System.Type typeSrc, System.Type typeDst);

What would you expect it to do if presented with, say, Random and
XmlDocument? Or WebRequest and Int32? Most conversions just don't make
sense. If they make sense, they should be supported by one or other of
the types (possibly using IConvertible).
 
And if they do make sense but don't exist, you can usually create a derived
class with an implicit or exlpicit conversion and implement the change
yourself.
 
Javier Ros said:
hi guys,

someone know if exists a function that convert a object from any type to
other type?

exaple:
ConvertFromTO(object obj, System.Type typeSrc, System.Type typeDst);

Check ChangeType method of Convert class.

HTH,
Maciej
 
Back
Top