Entwickler-Ecke

Basistechnologien - Variablen Name hochzählen


paddy14 - Do 07.04.11 09:37
Titel: Variablen Name hochzählen
Guten Tag Forum,

denke mir mal das der Titel nicht so gut ist aber anderst konnte ich das nicht beschreiben.

Nun zu meiner Frage.

Bsp.: Ich habe diesen Aufbau,

TcpClient connection1 = Server.AcceptTcpClient();

TcpClient connection2 = Server.AcceptTcpClient();

TcpClient connection3 = Server.AcceptTcpClient();

TcpClient connection4 = Server.AcceptTcpClient();

meine Frage ist wie bekomme ich das hin das ich in einer Schleife die connections hochzählen lassen kann, so das ich beliebig viele davon haben kann und nicht wie in dem Bsp.???


Danke für eure Antwort

Mfg Patrick


Th69 - Do 07.04.11 09:44

Hallo,

benutze eine List<TcpClient>:

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
List<TcpClient> connections = new List<TcpClient>();

while(true)
{
  TcpClient connection = Server.AcceptTcpClient();

  connections.Add(connection);
}


paddy14 - Do 07.04.11 11:31

Danke dir hat ir sehr geholfen :).