473,508 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do I need to Convert with Convert.ToInt32(session("myNumber")) ?

Hello,
I have this

session("myNumber") = 888
Dim intNumber As Integer

a) intNumber = session("myNumber")
b) intNumber = Convert.ToInt32(session("myNumber"))
What has better performance and what should I do?

Thanks,
Andreas
Nov 17 '05 #1
1 2185
You are clearly not programming with Option Strict on. You should turn it
on and then you wouldn't have a choice but to select the most performant and
safest method.

b) Explicietly converting is the best way to do it, spefically from a
perfromance point of view...otherwise you are late-binding...which is bad.

Alternative (and better) ways to write b) would be using cint() or
DirectCast...both of which should be faster than Convert.ToInt32 and are
recommeded by Microsoft. You should always explicetly convert. Session,
Application, Context, DataReader and DataRow objects are all great examples
of places that return object, but you are likely implicetly assigning to
ints or strings.

Also, some error handling would be nice ,no?

dim intNumber as integer
try
intNumber = cint(session("myNumber"))
catch ex as FormatException
'maybe you wanna redirect? Maybe you wanna set a default value
catch ex as OverflowException
'maybe you wanna redirect? Maybe you wanna set a default value
end try

Karl
"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Hello,
I have this

session("myNumber") = 888
Dim intNumber As Integer

a) intNumber = session("myNumber")
b) intNumber = Convert.ToInt32(session("myNumber"))
What has better performance and what should I do?

Thanks,
Andreas

Nov 17 '05 #2

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

Similar topics

3
11026
by: Graham Nicholls | last post by:
Hi, I'm trying to size a jpeg file. The file size is held in a short (2 byte integer) at a certain offset. Once I've found these two bytes (they're in MSB,LSB order), I need to convert them to...
0
879
by: Ignacio Marcos | last post by:
Hi everyone! I need to convert a gif image (phisical file on my server) to jpg. I tried with the thumb function, but when i try to do thumb.Save(response.outputstream, Imaging.ImageFormat.Jpeg) it...
2
991
by: NATE | last post by:
I need a web control to browse a cube... I don't know how to use the OWC controls (COM controls in general), when I drag a COM control to my page I can't see all the properties and if I drag...
5
3414
by: Allerdyce.John | last post by:
Do I need to convert string to integer in python? or it will do it for me (since dynamic type)? In my python script, I have this line: x /= 10; when i run it, I get this error: TypeError:...
1
8725
by: Jack | last post by:
Hello, I need to convert a 'System.Xml.XmlNode' to a string. Any help would be great!!! Thanks, Jack
2
1163
by: rajivksh | last post by:
I'm stuck with a problem where I need to convert hastable contents to a object type at runtime... below is the code.. // Portfolio pf = GlobalVariables.portfolio; IEnumerator pfDealsEnum =...
2
4772
kamill
by: kamill | last post by:
I need to convert excel file into PDF file using PHP, how can i do it. I am able to generate a pdf file. Is there any solution to export excel data into mysql database? I am waiting for help.
3
1534
by: zaggi | last post by:
Hi, I need to convert HTML file to any image file. I need to get it done in c#.NET only. Could you please suggest me some ways of doing it. Thanks, Zaggi
0
7123
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...
0
7382
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...
0
7495
tracyyun
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...
0
5627
agi2029
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,...
1
5052
isladogs
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...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
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 ...
0
418
bsmnconsultancy
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...

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.