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 / New Users / January 2005

Tip: Looking for answers? Try searching our database.

String conversion from an Object in VB.NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marlon - 04 Jan 2005 14:23 GMT
Which statement gives better performance (where obj can contain any of the
CLR runtime types)

1)  CStr(obj)

or

2) obj.ToString()
Nick Malik [Microsoft] - 04 Jan 2005 15:09 GMT
They are essentially the same.  CStr(obj) will generate a bit more IL code
than obj.ToString() because it is a call to a function that will turn around
and call ToString anyway.

If you are interested in performance, this article may help:
http://accessvbsql.advisor.com/doc/12798

Signature

--- Nick Malik [Microsoft]
   MCSD, CFPS, Certified Scrummaster
   http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
  I do not answer questions on behalf of my employer.  I'm just a
programmer helping programmers.
--

> Which statement gives better performance (where obj can contain any of the
> CLR runtime types)
[quoted text clipped - 4 lines]
>
> 2) obj.ToString()
Steven Cheng[MSFT] - 05 Jan 2005 03:44 GMT
Hi Marlon,

From a general view, I always think call obj(or other class's ) ToString
will be better if there is no particular requirement ot use any Convert
class to do the same task. And as for the CStr, this is a visualbasic
compatible expression which is actually translated to the following call at
runtime:

Microsoft.VisualBasic.CompilerServices.StringType.FromObject(Object value)
in microsoft.visualbasic.dll

And the StringType.FromObject will also do a switch list to compare the
object's Typecode and do the convertion. So I think directly use ToString()
method is always the preferred way.
Do you think so?

thanks.

Regards,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


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.