monica73174
asked on
In C# how to name variables dynamically
]I need to create an a variable set to an object dynamically using the code below. There can be anywhere from 0 to many so I need to set lr with a numeric value for example lr1, lr2 etc... I am realizing what I have below cannot be done with a simple concatination.
[embed=snippet 8250291
[embed=snippet 8250291
foreach (int i in labreports)
{
MHLServices.FaxQueueRequestILabReport "lr" + i.ToString() = new MHLServices.FaxQueueRequestILabReport();
lr + i.lr_uid = labreports.items[i];
fax.FaxQueueRequestILabReports.Add(lr + i);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Lists are dynamic. You create as many as you need.
http://dotnetanalysis.blogspot.com/2011/04/list.html
http://dotnetanalysis.blogspot.com/2011/04/list.html
Use a Dictionary:
http://msdn.microsoft.com/en-us/library/xfhwa508(VS.85).aspx
The variable name will be the key.
http://msdn.microsoft.com/en-us/library/xfhwa508(VS.85).aspx
The variable name will be the key.
ASKER