473,666 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hello,
I have this

session("myNumb er") = 888
Dim intNumber As Integer

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

Thanks,
Andreas
Nov 17 '05 #1
1 2198
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...otherwis e you are late-binding...which is bad.

Alternative (and better) ways to write b) would be using cint() or
DirectCast...bo th 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("m yNumber"))
catch ex as FormatException
'maybe you wanna redirect? Maybe you wanna set a default value
catch ex as OverflowExcepti on
'maybe you wanna redirect? Maybe you wanna set a default value
end try

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

session("myNumb er") = 888
Dim intNumber As Integer

a) intNumber = session("myNumb er")
b) intNumber = Convert.ToInt32 (session("myNum ber"))
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
11037
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 an integer - now I know that in C I'd just cast a pointer to the offset to a short, and that python doesn't cast, so how can I extract the value from a stream of bytes. I've looked at python.org/Doc/current (I'm using 2.3b1), but can't find...
0
885
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 does not work. Tanks a lot, cya.
2
997
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 another COM control, for example a button I see the same properties... Do I need to convert the COM controls to .Net controls or something like that??? thanks...
5
3429
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: unsupported operand type(s) for /=: 'unicode' and 'int' I want to divide x by 10 and assign that value back to x.
1
8759
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
1169
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 = pf.getPortfolioDeals().GetEnumerator(); while (pfDealsEnum.MoveNext()){ Deal deal = (Deal)pfDealsEnum.Current; }
2
4785
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
1543
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
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8863
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, 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...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7378
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, 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...
0
5661
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();...
0
4192
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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
2
1763
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 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...

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.