In service, use string to refer to array I should use?

  • Thread starter Thread starter pantagruel
  • Start date Start date
P

pantagruel

Hi,

I have a service which does posting of messages dependent on CSV
input. Dependent on what the first line of the CSV is different fields
must be extracted and placed into a message. I would like to do it in
the following manner:

x = string value of csv field.

get array name = value of x

so if x = "Y"

then I can do Y[1] and so forth. I would like to avoid having this
using a bunch of logic to return the arrays, is there anything in .Net
or Csharp that allows this kind of thing? Is reflection the answer?
and if so can someone point me to some relevant examples?
Thanks.
 
You could use a Dictionary like so:

....
string x = "Y";
Dictionary<string, string[]> dict = new Dictionary<string,
string[]>();
dict.Add(x, new string[]{x});
Console.WriteLine("value of {0} is {1}", "Y", dict["Y"][0]);
....

==================
Regards,
Steve
www.foxville.ch
 

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