hawaiiantrash
Programmer
im trying to store arraylists in a dictionary .. i dont thikn im doing this right because when i output .. i get 3 results .. b1,b2,and a collections object .. the end goal is to have a running list of channels (chat rooms) and their users (username,socketconnection) .. so when i need to send a message to a certain room i can simply use a key to pull the users and then loop through the results to get the users socket and send them a message
here is my code i have so far:
using System;
using System.Collections;
using System.Collections.Generic;
class Test
{
static void Main()
{
Dictionary<String,ArrayList> clientlist = new Dictionary<String,ArrayList>();
ArrayList clientinfo = new ArrayList();
// create channel
clientinfo.Add("a1");
clientinfo.Add("a2");
clientlist.Add("channel1",clientinfo);
clientinfo.Clear();
// add onto existing channel (key)
clientinfo.Add("b1");
clientinfo.Add("b2");
((ArrayList)clientlist["channel1"]).Add(clientinfo);
ArrayList results = (ArrayList)clientlist["channel1"];
Console.WriteLine("results size: " + results.Count);
for (int i = 0; i < results.Count; i++)
{
Console.WriteLine(results);
}
System.Threading.Thread.Sleep(5000);
}
}
perhaps im approaching this the wrong way even, please advise
thanks!
here is my code i have so far:
using System;
using System.Collections;
using System.Collections.Generic;
class Test
{
static void Main()
{
Dictionary<String,ArrayList> clientlist = new Dictionary<String,ArrayList>();
ArrayList clientinfo = new ArrayList();
// create channel
clientinfo.Add("a1");
clientinfo.Add("a2");
clientlist.Add("channel1",clientinfo);
clientinfo.Clear();
// add onto existing channel (key)
clientinfo.Add("b1");
clientinfo.Add("b2");
((ArrayList)clientlist["channel1"]).Add(clientinfo);
ArrayList results = (ArrayList)clientlist["channel1"];
Console.WriteLine("results size: " + results.Count);
for (int i = 0; i < results.Count; i++)
{
Console.WriteLine(results);
}
System.Threading.Thread.Sleep(5000);
}
}
perhaps im approaching this the wrong way even, please advise
thanks!