|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Difference between Cint and Convert.ToInt32 ?Hello
txtID.Text contains a 6 digit Integer number with no decimals, no chars... Dim j As Integer = Cint(txtID.Text) or Dim j As Integer = Convert.ToInt32(txtID.Text) Is there any difference between these 2 statements? Is one statement more correct than the other? Thanks, Rich Rich wrote:
<snip> > txtID.Text contains a 6 digit Integer number with no decimals, no chars... <snip>> > Dim j As Integer = Cint(txtID.Text) > > or > > Dim j As Integer = Convert.ToInt32(txtID.Text) > > Is there any difference between these 2 statements? Is one statement more > correct than the other? Well, there *is* a difference: any the following literals would raise an exception if Convert.ToInt32 was used instead of CInt: ? CInt("123.456") ? CInt("123,456") ? CInt("&h123") In other words, CInt (when passed a string) performs more work than Convert.ToInt32. Regards, Branco Thanks. I guess I will stay with Convert.ToInt32.
Rich Show quoteHide quote "Branco Medeiros" wrote: > > Rich wrote: > <snip> > > txtID.Text contains a 6 digit Integer number with no decimals, no chars... > > > > Dim j As Integer = Cint(txtID.Text) > > > > or > > > > Dim j As Integer = Convert.ToInt32(txtID.Text) > > > > Is there any difference between these 2 statements? Is one statement more > > correct than the other? > <snip> > > Well, there *is* a difference: > > any the following literals would raise an exception if Convert.ToInt32 > was used instead of CInt: > > ? CInt("123.456") > ? CInt("123,456") > ? CInt("&h123") > > In other words, CInt (when passed a string) performs more work than > Convert.ToInt32. > > Regards, > > Branco > > "Rich" <R***@discussions.microsoft.com> schrieb: Not really. I'd try to avoid 'Convert.ToInt32' and use 'CInt' or > txtID.Text contains a 6 digit Integer number with no decimals, no chars... > > Dim j As Integer = Cint(txtID.Text) > > or > > Dim j As Integer = Convert.ToInt32(txtID.Text) > > Is there any difference between these 2 statements? Is one statement more > correct than the other? 'Integer.Parse' instead. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Rich,
Yes there are, Convert.ToInt32 is longer and it converts to Int32 CInt converts to Integer what should be represent the best internal format to use by the computer. Unlucky enough has a big lobby changed the last for the 64bit version and are there extra instructions needed now (they are fast but still take time). Cor Show quoteHide quote "Rich" <R***@discussions.microsoft.com> schreef in bericht news:8BE53B5A-DA04-4844-B911-DC42E14797C0@microsoft.com... > Hello > > txtID.Text contains a 6 digit Integer number with no decimals, no chars... > > Dim j As Integer = Cint(txtID.Text) > > or > > Dim j As Integer = Convert.ToInt32(txtID.Text) > > Is there any difference between these 2 statements? Is one statement more > correct than the other? > > Thanks, > Rich
Not first class in file
Coding style acceptable rounding practices in banking. Can't get <ToolboxBitmap> to work! Program flow with multi-threading app - corrupted datatables where to store sound file How can I to pass an array to a DLL function? WebBrowser control not responding to SetScroll API spurious error 2005 Express Version |
|||||||||||||||||||||||