Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / June 2005

Tip: Looking for answers? Try searching our database.

casting vs. the convert class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
comp_sci_kid - 03 Jun 2005 00:31 GMT
hi everyone

which is more efficient: casting or using the convert class? please give
reasons.

tia
Miha Markic [MVP C#] - 03 Jun 2005 12:28 GMT
Casting is certainly faster while converting is more flexible (it can
convert various types while cast doesn't convert).

Signature

Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

> hi everyone
>
> which is more efficient: casting or using the convert class? please give
> reasons.
>
> tia
john conwell - 15 Jun 2005 16:49 GMT
wooo...hold on there.  It depends on what type to what type your casting.  
If you take a look at the Convert class using Reflector
(www.aisto.com/roeder/dotnet) most of the methods in Convert do a straight
cast.  convertions that can be safely casted are just casted.  Others are
checked for upper and lower bounds and throw exceptions of it wont be a safe
cast (long to an int).  Some methods just return the passed in value (int to
an int).

Best thing to do when you want to know how somethign works...look at the
code in Reflector

> Casting is certainly faster while converting is more flexible (it can
> convert various types while cast doesn't convert).
[quoted text clipped - 5 lines]
> >
> > tia

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.