Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a array with some values. What i want to do is to loop through the array elements and create an object ( a custom connection manager to a asterisk server in particular) named after an array element.

for (int k = 0; k < servers.Count; k++)
           {

   connectionk = new connection(servers[0].tostring());

   }

I cant figure out a way to name the connection with an dynamic name , like connection0 for example (where 0 is the value of k).

Any help ?
Posted
Updated 3-Jan-10 3:32am
v2

Use a Dictionary object.

So your code will look something like

for (int k = 0; k < servers.Count; k++)
{ 
    Dictionary<string,object> objConnection;
    objConnection.Add(servers[0].tostring(),new connection());
}
 
Share this answer
 
v2
Why do you want to create connection variable names like this. Create an array/list of connection to do this. :-D

List<Connection> lcon = new List<Connection>();
for (int k = 0; k < servers.Count; k++)
{
   lcon.add(new connection(servers[0].tostring()));
}

Now find all the objects in lcon. :rose:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900