Which one is better to use? CInt(string) or Integer.Parse(s tring)? thanks!
Nov 20 '05
15 27856
* "Brian Henry" <br**********@n ewsgroups.nospa m> 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 interoperabilit y and more than one .NET programming language
are useless.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
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**********@n ewsgroups.nospa m> wrote in message
news:OC******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP11.phx.gbl...* "Brian Henry" <br**********@n ewsgroups.nospa m> 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/>
"Brian Henry" <br**********@n ewsgroups.nospa m> wrote in message
news:ua******** ******@TK2MSFTN GP12.phx.gbl... Which one is better to use? CInt(string) or Integer.Parse(s tring)?
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.
Sorry. Ignore my previous message.
You can use something like Integer.Parse(" 1,234",
Globalization.N umberStyles.Any ) to convert that string.
"Marc" <no****@nospam. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl... "Brian Henry" <br**********@n ewsgroups.nospa m> wrote in message news:ua******** ******@TK2MSFTN GP12.phx.gbl... Which one is better to use? CInt(string) or Integer.Parse(s tring)? 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.
* Marc <no****@nospam. com> scripsit: Which one is better to use? CInt(string) or Integer.Parse(s tring)? 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/>
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******** ******@TK2MSFTN GP09.phx.gbl... * "The Grim Reaper" <gr*********@bt openworld.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.Visua lBasic 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/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kenneth |
last post by:
What's the different between this
CInt(iID)
Integer.Parse(iID)
|
by: Atara |
last post by:
In my apllication I use the following code:
'-- My Code:
Public Shared Function strDate2Date(ByVal strDate As String) As
System.DateTime
Dim isOk As Boolean = False
If (strDate Is Nothing) Then
isOk = False
ElseIf Not (strDate.Length() = 6) Then
isOk = False
|
by: Teresa |
last post by:
1) Should I use Integer.Parse to convert a string into an integer in .NET
now?
CType(sUserID, Integer) OR Integer.Parse(sUserID)
2) And is it better to use the string class to trim, get length, etc in .NET?
s1.trim OR trim(s1)
s1.length OR len(s1)
Thank you!
|
by: Jim in Arizona |
last post by:
I'm familiar with CInt(value) but I'm not with Int32.Parse(value). They seem
to do the same thing. Is there a big difference between the two and when
would one be best applied over the other?
Thanks,
Jim
|
by: Joergen Bech |
last post by:
Basically, I want to convert hex values in the range
"00000000" to "FFFFFFFF" to a signed, 32-bit Integer
value.
In VB6, I could just write lngValue = Val(hexstring$).
In VB.Net, I seem to be forced to do something like
---snip---
Private Function HexToInteger(ByVal hexValue As String) As Integer
| |
by: Joe |
last post by:
Hello All:
Does anyone know the difference between CType(x,Integer) vs.
Integer.Parse(x)? Is there a performance advantage to one or the other?
TIA,
--
Joe
|
by: Rich |
last post by:
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)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |