Ask a Question related to ASP.NET General, Design and Development.
-
Andreas Klemt #1
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
Andreas Klemt Guest
-
convert XML "values" to be passed as CDATA into Flash
Hello all, I found the following XML - Flash quiz template on the net and I was wondering how can I adapt the XML doc to pass CDATA instead of... -
How to "Convert To Template" in custom control
OK, so I think for my last post, what I really want to do is implement my own "Convert to Template" which will create my own template. Could... -
Stop popup " do you wish to convert existing data"
I cannot stand that Freehand 10 gives me a popup box asking "do you wish to convert the existing date on the clipboard before existing?" everytime I... -
AI CS does not "Convert to Working Space"
I have several hundred AI 10 files that I want to convert to CS. The AI 10 files have no embedded ICC Profile, but the AI CS files will all have... -
convert visual basic "string" data type to DB2 "blob"
Does anyone know if a visual basic string data type can be converted to DB2 blob datatype? I have all data in XML files and I use Visual Basic to... -
Karl Seguin #2
Re: Do I need to Convert with Convert.ToInt32(session("myNumber")) ?
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" <aklemt68@hotmail.com> wrote in message
news:ujlU9nSUDHA.2008@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
>
>
Karl Seguin Guest



Reply With Quote

