By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,671 Members | 1,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,671 IT Pros & Developers. It's quick & easy.

Covert to typeB from typeA

P: n/a
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);
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Javier Ros <jros@NO$PAMHEREemuasa.es> wrote:
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).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #2

P: n/a
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.

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP***********************@news.microsoft.com. ..
Javier Ros <jros@NO$PAMHEREemuasa.es> wrote:
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).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 13 '05 #3

P: n/a
"Javier Ros" <jros@NO$PAMHEREemuasa.es> wrote in message
news:e8**************@tk2msftngp13.phx.gbl...
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
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.