I am not a .net developer, and I need to assign 35 values to the inputs of a external method using .net 3.5. The method inputs look something like this:
proc.x1 = "ABC"
proc.x2 = "DEF"
...
proc.x35 = "ZZZ"
I'm getting the values I need to assign by parsing a delimited string into a dictionary, with the ordinal position of each substring as my key value.
string proccode = "9052 9|9605 9|966 9|9607 9|4311 9";
foreach (string xProc in proccode.Split('|'))
{
procs.Add(iProc, xProc.Substring(0, 7) + "Y");
Console.WriteLine(aProc + " " + iProc);
aProc = aProc + xProc.Substring(0, 7);
iProc = iProc + 1;
}
1 or all of the key values may not exist. (the entire string can be null; the above example only has 5).
I'm currently using the code below 35 times to assign the values to the variables (which I learned here):
if(diags.TryGetValue(1, out value))
{
proc.x1=diags[1];
}
But repeating this code 35 times seems like poor design.
Once I've assigned all of the inputs, the external code does something in a black box:
proc.Calc()
It returns a bunch of unrelated values (correctly).
Is there a superior way to accomplish this?