By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Cint or Integer.Parse?

P: n/a
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!
Nov 20 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!


Personal preference.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!


Depends on whether you want to retain the VB "feel" or go hardcore Framework
all the way.
Nov 20 '05 #3

P: n/a
been trying to knock out all the old vb stuff out of my head so sounds like
the parse one is good to go with :)
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:Of**************@tk2msftngp13.phx.gbl...

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
Which one is better to use? CInt(string) or Integer.Parse(string)?
thanks!
Depends on whether you want to retain the VB "feel" or go hardcore Framework all the way.

Nov 20 '05 #4

P: n/a
Brian,
I would use CInt, unless I specifically needed to use Integer.Parse. As
Herfried stated its largely personal preference.

For details on CInt vs. Integer.Parse and details on other myths about
avoiding VB in your VB.NET see:

http://www.panopticoncentral.net/arc...5/31/1100.aspx

http://www.panopticoncentral.net/arc...6/07/1200.aspx

Hope this helps
Jay
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!

Nov 20 '05 #5

P: n/a
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
been trying to knock out all the old vb stuff out of my head so sounds like
the parse one is good to go with :)


'CInt' is not "old vb". It's current VB syntax that /should/ be used
/instead/ of the framework functions whenever possible. That's why we
have these commands.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6

P: n/a
I agree that Integer.Parse is the wrong thing to use - but CType(xx,
Integer) is functionally identical to CInt - and if you happen to not have
Microsoft.VisualBasic referenced... it's fine :D
_______________________________
The Grim Reaper

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
been trying to knock out all the old vb stuff out of my head so sounds like the parse one is good to go with :)


'CInt' is not "old vb". It's current VB syntax that /should/ be used
/instead/ of the framework functions whenever possible. That's why we
have these commands.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7

P: n/a
* "The Grim Reaper" <gr*********@btopenworld.com> scripsit:
I agree that Integer.Parse is the wrong thing to use - but CType(xx,
Integer) is functionally identical to CInt - and if you happen to not have
Microsoft.VisualBasic referenced... it's fine :D


Both, 'CInt' and 'CType' are VB /keywords/ that should work without
referencing this library.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

P: n/a
any reason specific reason why you suggest i should use CInt instead of the
framework versions? I'm trying to maintain as much compatability in tearms
of code with C# incase they ever want this code directly coverted over to
it..
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
been trying to knock out all the old vb stuff out of my head so sounds
like
the parse one is good to go with :)


'CInt' is not "old vb". It's current VB syntax that /should/ be used
/instead/ of the framework functions whenever possible. That's why we
have these commands.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #9

P: n/a
Hi Brian,

One of the things in the language itself where VB is much better than all
the other languages in dotNet are the *convert* functions.

You have the change to use that benefit, not using them is for me the same
as getting a million and not accepting it because it is not given to
everybody.

Just my thougth,

Cor

Nov 20 '05 #10

P: n/a
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
any reason specific reason why you suggest i should use CInt instead of the
framework versions? I'm trying to maintain as much compatability in tearms
of code with C# incase they ever want this code directly coverted over to
it..


Readability. Code is more compact, there is no useless stuff like
'Parse'. It's like using '+' instead of 'op_Addition'. If we start
using the greatest common subset of language features in our code,
language interoperability and more than one .NET programming language
are useless.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11

P: n/a
Brian,
Because CInt may actually be faster then Integer.Parse or Convert.ToInt.

http://www.panopticoncentral.net/arc...5/31/1100.aspx

http://www.panopticoncentral.net/arc...6/07/1200.aspx
Using Integer.Parse, "cause its more C#" may actually be developing bad
habits. In that you will use Integer.Parse or Convert.ToInt "cause its more
..NET", where as if this was C# code I am sure you would have no problems
using an (int) cast. Guess what CInt is both an (int) cast & a
Convert.ToInt! VB.NET picks the correct on based on usage. Somehow that
makes it more preferred in my book, rather then less preferred... More RAD
somehow...
I'm trying to maintain as much compatibility in terms
of code with C# incase they ever want this code directly converted over to
it.. I would worry about conversion when the conversion actually happened,
allowing me to write "correct" VB.NET code, by "correct" I mean use the
correct feature for the correct problem. If you want to use VB.NET to write
C# code, I would strongly recommend you use C# to write C# code!

As a friend of mine says: avoiding CInt in VB.NET is like buying a new car
and avoiding using the power windows.

Just a thought
Jay
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:OC**************@TK2MSFTNGP09.phx.gbl... any reason specific reason why you suggest i should use CInt instead of the framework versions? I'm trying to maintain as much compatability in tearms
of code with C# incase they ever want this code directly coverted over to
it..
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
been trying to knock out all the old vb stuff out of my head so sounds
like
the parse one is good to go with :)


'CInt' is not "old vb". It's current VB syntax that /should/ be used
/instead/ of the framework functions whenever possible. That's why we
have these commands.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #12

P: n/a

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!


Another thing to consider is that CInt will convert the string
"1,000", whereas Integer.Parse will not; you'll get an exception.

Marc.
Nov 20 '05 #13

P: n/a
Sorry. Ignore my previous message.
You can use something like Integer.Parse("1,234",
Globalization.NumberStyles.Any) to convert that string.

"Marc" <no****@nospam.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
Which one is better to use? CInt(string) or Integer.Parse(string)?

thanks!


Another thing to consider is that CInt will convert the string
"1,000", whereas Integer.Parse will not; you'll get an exception.

Marc.

Nov 20 '05 #14

P: n/a
* Marc <no****@nospam.com> scripsit:
Which one is better to use? CInt(string) or Integer.Parse(string)?

thanks!

Another thing to consider is that CInt will convert the string
"1,000", whereas Integer.Parse will not; you'll get an exception.


That depends on your system's number style settings...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #15

P: n/a
Yes, you're quite right. I must have been more tired than I thought at 1am
this morning!!
I was thinking of the Asc() function - sorry.
___________________________________
The Grim Reaper

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
* "The Grim Reaper" <gr*********@btopenworld.com> scripsit:
I agree that Integer.Parse is the wrong thing to use - but CType(xx,
Integer) is functionally identical to CInt - and if you happen to not have Microsoft.VisualBasic referenced... it's fine :D


Both, 'CInt' and 'CType' are VB /keywords/ that should work without
referencing this library.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.