Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cast vs .ToString()
Message
 
To
15/12/2003 14:26:25
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00859235
Message ID:
00859752
Views:
12
>Anybody know off-hand which is faster (or does it really matter <g>)? I would think that the cast would be faster, or better, but I don't really know.
>
>string x = row["MyColumn"].ToString();
>
>or
>
>string x = (string)row["MyColumn"];
>
>This is assuming that you already know that row["MyColumn"] cannot be DBNull.Value.
>
>TIA,
>~~Bonnie

I believe that a cast will take the object reference and use that to assign the value to x and then link the objects. I know if you use the ToString() method, there is a function call that takes place which requires a stack operation, the creation of a string variable, processing, return, stack operation, then assignment.

The cast would be significantly faster if my assumptions are correct, but you will need to add a check for the null value before hand.

If I am wrong, please let me know.
Brian Seekford
Seekford Solutions, Inc.
http://www.SeekfordSolutions.com
Internet ActiveX Controls and .NET Class Libraries.
SMTP/S FTP POP3/S HTTP/S SNTP MIME PING WHOIS TRACEROUTE NNTP DNS MX
Base64, UUEncode, yEnc, MD5, SHA1, URL, Quoted-Printable.
Resizer and Tooltips
Email Verification and more. Check us out!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform