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
 
Back
Top