Performance- Code Snippet

Hello,
Any suggestions for improvement in this code snippet, performance wise [expecially since we have Generics in .net 2.0]

Dim arr() As String = Split(PageRange, "-")
Dim StartPage As Integer = CInt(arr(0))
Dim EndPage As Integer = CInt(arr(1))


Answer this question

Performance- Code Snippet

  • jitendra badkas

    Thanks for the responses. Split function by default returns a 1-dimensional string array. This forces me to declare my array variable as "string" although i know that my array only has integers. I think there is a performance penalty in doing the boxing from "string" to "int" on each array element.May be I can have a "(Type T() of Integer) and use a function that splits a string into a 1-dimensioanl array of integers so that I don't have to do the cast from string to int

    Thanks,
    Prakash

  • engloon

    The original value (PageRange) is a string to start with so no matter how you parse it you'll have to convert the values from strings to integers.

  • Sandrina

    And the split method works with a string - so calling this is splitting a string to make and array of string based upon the separator characters.

    Generics is not going to help you here - as the method itself is based around splitting a string.


  • camtx1400

    Depending on what you are doing, if this operation is being done multiple times a session, then a compiled Regular Expression to parse out the items may give you a speed enhancement over the split.


  • MarsDK

    Not really... looks fine as-is

  • Performance- Code Snippet