How would you handle this? array or object?

  • Thread starter Thread starter Kevin Blount
  • Start date Start date
K

Kevin Blount

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.GetUpperBound 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#
 
Kevin Blount said:
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.

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

Having several variables for data which is intrinsically connected like
this isn't a good idea.
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'

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top