strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juli jul

    #1

    strings

    Hello ,
    wanted to know if it's possible to create a set (enum or array) of
    strings and than make the IndexOf method on it.
    I have 6 strings and I want to chack if the string I read is one of them
    (with IndexOf!=-1)
    How to do it the best?
    Thanks a lot

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Jon Skeet [C# MVP]

    #2
    Re: strings

    juli jul <juli8024@yahoo .com> wrote:[color=blue]
    > wanted to know if it's possible to create a set (enum or array) of
    > strings and than make the IndexOf method on it.
    > I have 6 strings and I want to chack if the string I read is one of them
    > (with IndexOf!=-1)
    > How to do it the best?[/color]

    Yes, just create a string array and then use the static Array.IndexOf
    method. Alternatively, put them in an ArrayList and use the instance
    method ArrayList.Index Of.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • juli jul

      #3
      Re: strings

      I am doing it in if with all the strings,could it slow down the
      performance or it supposed to be the same as with an array?



      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: strings

        juli jul <juli8024@yahoo .com> wrote:[color=blue]
        > I am doing it in if with all the strings,could it slow down the
        > performance or it supposed to be the same as with an array?[/color]

        I'm not entirely sure what you're asking - are you asking if the
        performance of Array.IndexOf is the same as ArrayList.Index Of? If so, I
        suspect the difference (if any) is going to be negligible compared with
        most other aspects of your program.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...