How would you handle this? array or object?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Blount

    How would you handle this? array or object?

    Let me first state that I'm a new C# (ASP.NET) developer, spending the
    last 8 years with ASP and having attended 2 fairly basic ASP.NET
    courses, so my knowledge is a dangerous case of "I know how to do that
    in ASP, so it must be possible in ASP.NET"

    Here's what I want to do, which oddly is not something I've done in
    ASP:

    I have a set of string in pairs, such as

    sUsernameAAA = "aaa"
    sPasswordAAA = "aaap"

    sUsernameBBB = "bbb"
    sPasswordBBB = "bbbp"

    sUsernameCCC = "ccc"
    sPasswordCCC = "cccp"

    up to, say, FFF.

    I pass to a function that uses these a string such as "bbb". I want to
    loop through all these values until a match on a 'Username' is found,
    and then set a new variable to be the corresponding 'Password'

    my thought was that I could create an Array, such as "string[,]
    myStrings { {"aaa","aaap "} {"bbb","bbbp "} {"ccc","cccp "} ... } and then
    use a loop from 0 to myString.GetUpp erBound and check against the first
    dimension until a match is found, then set the new password variable to
    the second dimension.

    Does that make sense? If so, is it a good method?

    I was also wondering if an object could be used, though I'm not really
    sure what I'm talking about here, but figured someone might ;)

    any comments would be appreciated, as long as they are constructive and
    understanding of my newness to ASP.NET and C#

  • Jon Skeet [C# MVP]

    #2
    Re: How would you handle this? array or object?

    Kevin Blount <kevin.blount@g mail.com> wrote:[color=blue]
    > Let me first state that I'm a new C# (ASP.NET) developer, spending the
    > last 8 years with ASP and having attended 2 fairly basic ASP.NET
    > courses, so my knowledge is a dangerous case of "I know how to do that
    > in ASP, so it must be possible in ASP.NET"
    >
    > Here's what I want to do, which oddly is not something I've done in
    > ASP:
    >
    > I have a set of string in pairs, such as
    >
    > sUsernameAAA = "aaa"
    > sPasswordAAA = "aaap"
    >
    > sUsernameBBB = "bbb"
    > sPasswordBBB = "bbbp"
    >
    > sUsernameCCC = "ccc"
    > sPasswordCCC = "cccp"
    >
    > up to, say, FFF.[/color]

    That immediately suggests to me that you want a list or an array, with
    each element being a reference to an instance of a UsernamePasswor d
    class (or something like that).

    Having several variables for data which is intrinsically connected like
    this isn't a good idea.
    [color=blue]
    > I pass to a function that uses these a string such as "bbb". I want to
    > loop through all these values until a match on a 'Username' is found,
    > and then set a new variable to be the corresponding 'Password'[/color]

    If that's all you need to do with them, use a map
    (Dictionary<Str ing,String> in 2.0 or Hashtable in 1.1) with the
    usernames as the keys and the passwords as the values.

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too

    Comment

    • Kevin Blount

      #3
      Re: How would you handle this? array or object?

      Jon,

      Thanks for the response (I was hoping you'd see this one <g>)

      I'll work with the Hashtable (as I'm using 1.1) and see how I get on.

      Cheers

      Kevin

      Comment

      Working...