473,386 Members | 1,796 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,386 software developers and data experts.

Advantage between (int) and Convert.ToInt32?

Is there any advantage, or a recommended preference, between using (int) or
Convert.ToInt32() to convert numeric types to System.Integer32 ?

Thanks,
Nov 16 '05 #1
1 1172
Hi,

They are two different concepts, the first is a cast , for this to work the
casted type should be convertible to int , no all of the types are.

The second are a series of method with different signatures, each overloaded
version perform the needed conversion.

IMO a cast should be faster than calling Convert.XXX but I cannot garantee
it, it does depend of the typed being converted.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Is there any advantage, or a recommended preference, between using (int)
or
Convert.ToInt32() to convert numeric types to System.Integer32 ?

Thanks,

Nov 16 '05 #2

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

Similar topics

5
by: John Smith | last post by:
Hey folks, I know this is an old topic, but I can't find a definitive answer on google. How do I tell if an int has been initialized or not? I had been testing it like: if(myInt ==...
8
by: Jarod | last post by:
Hey I have following "problem". int id = (int)SQlHelper.ExecuteScala(...) - it returns object ( which is int ) I get invalid cast. Convert.ToInt32(...) works ok. Why ? Jarod
5
by: Asha | last post by:
greetings, i'm converting my value to int value using int32.parse() the problem is that, if its an empty value it returns me an error. what can i do to handle this error besides using a if...
5
by: Galahad | last post by:
I am using the code below to create a integer array. while(dr.Read()) { string StateID=dr.ToString(); int FacilityID=Convert.ToInt32(dr.ToString()); int FacilityIDs={FacilityID}; } ...
11
by: Code[R] | last post by:
hello all, i've a problem :s i've tried to convert a "system::string" (a textbox) to an "int" but i have only found a function to convert system::string to char and char to int :s : ...
17
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
2
by: tony | last post by:
Hello!! string number = "13"; int num; Is it exactly the same if I use num = Convert.ToInt32(number); OR num = int.Parse(number) Is it always in this case that I can choose whichever of...
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
6
by: Tony | last post by:
Hello! It seems to me that both Int32.Parse(..) and Convert.ToInt32(...) static methods works in exactly the same way. Both can throw an exeption. So is it any different at all between these...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.