Link to home
Start Free TrialLog in
Avatar of monica73174
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
         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);
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of monica73174
monica73174

ASKER

I just have no idea how many I  need to create.
Lists are dynamic.  You create as many as you need.

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.