473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Cast, Convert, Parse

Ant
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant
Nov 17 '05 #1
6 5899
Hi,

I quick browse thru reflector shows that Convert.ToInt32 internally calls
Int32.Parse.

However, in the IL still they are two different calls. So I guess
Int32.Parse is faster as it has one method call lesser.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Ant" wrote:
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant

Nov 17 '05 #2
Hi,

I quick browse thru reflector shows that Convert.ToInt32 internally calls
Int32.Parse.

However, in the IL still they are two different calls. So I guess
Int32.Parse is faster as it has one method call lesser.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Ant" wrote:
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant

Nov 17 '05 #3
Talking about casting, it's not supported...
(int)stringValue would cause a build error.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Rakesh Rajan" wrote:
Hi,

I quick browse thru reflector shows that Convert.ToInt32 internally calls
Int32.Parse.

However, in the IL still they are two different calls. So I guess
Int32.Parse is faster as it has one method call lesser.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Ant" wrote:
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant

Nov 17 '05 #4
Talking about casting, it's not supported...
(int)stringValue would cause a build error.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Rakesh Rajan" wrote:
Hi,

I quick browse thru reflector shows that Convert.ToInt32 internally calls
Int32.Parse.

However, in the IL still they are two different calls. So I guess
Int32.Parse is faster as it has one method call lesser.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Ant" wrote:
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant

Nov 17 '05 #5
Try to search before you post. There's answer to your question not long time
ago.

http://groups-beta.google.com/group/...b0a621b564ba9f

"Ant" <An*@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant

Nov 17 '05 #6
Try to search before you post. There's answer to your question not long time
ago.

http://groups-beta.google.com/group/...b0a621b564ba9f

"Ant" <An*@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.

When would it be best to use casting over Converting e.g.

(int)stringValue as opposed to

Convert.ToInt(stringValue)

or Parse for that matter:

Int32.Parse(stringValue);
small matters, but interesting to me.

Any ideas would be happily taken on board

Thanks in advance
Ant

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mp | last post by:
How do i cast a string from sql to a long? lDocumentVersion is long, oSqlDR.GetValue(0) returns a string. lDocumentVersion =oSqlDR.GetValue(0); Thanks
3
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object...
0
by: Ant | last post by:
Hi, I'm trying to find out the benefits of one type of conversion method over another. When would it be best to use casting over Converting e.g. (int)stringValue as opposed to ...
6
by: toebens | last post by:
Hi, i read this http://msdn.microsoft.com/chats/transcripts/vstudio/05_0811_dn_csharp.aspx : Cyrusn_MS (Expert): Q: please explain the difference 1: Convert.ToInt32(o) 2: (int)o 3: o as...
1
by: Lenn | last post by:
Hello, Here's a little background. I have a function that calls a method of another assembly (COM Interop) dynamically through Reflection. It gets method name and array of values and calls...
1
by: tshad | last post by:
I have a field that I read from my database that is a bit field field into a textbox. The Trace on the variable (MyInfoCreated) shows it as "False" - as you can see from the error. I tried it...
2
by: elena | last post by:
Hi, All Please, i need help with cast string to DateTime: DateTime dt = new DateTime(2006,09,17); it works i can update Field in Access DB Next field is Short Time data type, how i can cast...
15
by: soni2926 | last post by:
Hi, I have the following: float.Parse(myproduct.Price.Value.ToString()); myproduct.Price.Value.ToString() returns $24.00 (with the $) Is there anyway to do the above cast, I know the...
6
by: etienne | last post by:
Hello, I am looking for help for a cast problem: I want to run functions in thread, using the pthread_create function. The function to run is the first argument of pthread_create and is expected...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.