C# 使用列表连接&;断开
这里是Connect();功能:C# 使用列表连接&;断开,c#,list,C#,List,这里是Connect();功能: public static void Connect(string username, string password, string roomName, string roomType, string roomID, string roomPass, bool roomVisible) { Console.WriteLine("[Bot] Trying to login..."); PlayerIO.QuickConnect.SimpleCo
public static void Connect(string username, string password, string roomName, string roomType, string roomID, string roomPass, bool roomVisible)
{
Console.WriteLine("[Bot] Trying to login...");
PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", username, password,
delegate(Client client)
{
Console.WriteLine("[Bot] Logged in. Trying to join the room...");
Dictionary<string, string> roomData = new Dictionary<string, string>();
Dictionary<string, string> joinData = new Dictionary<string, string>();
roomData.Add("editkey", roomPass);
roomData.Add("name", roomName);
joinData.Add("editkey", roomPass);
try
{
con = client.Multiplayer.CreateJoinRoom(roomID, roomType, roomVisible, roomData, joinData);
if (con.Connected)
{
con.Send("init");
con.Send("init2");
con.OnMessage += new MessageReceivedEventHandler(OnMessage);
con.OnDisconnect += delegate(object sender, string reason)
{
Console.WriteLine("Disconnected, Error: " + reason);
};
Console.WriteLine("[Bot] Joined the world.");
}
}
catch (PlayerIOError error)
{
Console.WriteLine("Error: " + error);
}
},
delegate(PlayerIOError error)
{
Console.WriteLine("Error: " + error);
});
}
publicstaticvoidconnect(字符串用户名、字符串密码、字符串roomName、字符串roomType、字符串roomID、字符串roomPass、boolroomvisible)
{
Console.WriteLine(“[Bot]正在尝试登录…”);
Playero.QuickConnect.SimpleConnect(“Everyone-edits-su9rn58o40itdbnw69plyw”、用户名、密码、,
代表(客户)
{
Console.WriteLine(“[Bot]已登录。正在尝试加入房间…”);
Dictionary roomData=新建字典();
Dictionary joinData=新字典();
添加(“编辑键”,roomPass);
roomData.添加(“名称”,roomName);
添加(“编辑键”,roomPass);
尝试
{
con=client.Multiplayer.CreateJoinRoom(roomID、roomType、roomVisible、roomData、joinData);
如果(con.已连接)
{
con.Send(“初始”);
con.Send(“init2”);
con.OnMessage+=新的MessageReceivedEventHandler(OnMessage);
con.OnDisconnect+=委托(对象发送方,字符串原因)
{
Console.WriteLine(“断开连接,错误:+原因”);
};
WriteLine(“[Bot]加入了世界。”);
}
}
捕获(播放错误)
{
Console.WriteLine(“错误:+错误”);
}
},
委托(播放错误)
{
Console.WriteLine(“错误:+错误”);
});
}
最终的目标是断开连接,我的朋友告诉我,这可以通过使用列表来实现。我不熟悉列表,也不知道如何使用它们
我所要求的是将其放在“列表”形式中,以便(我假设…)我们可以使用“清除”方法来断开连接。或者是“删除”方法
但正如我所说,我根本不知道如何使用列表,所以Clear方法可能意味着完全不同的东西
请询问您是否需要了解有关此功能的更多信息,我会尽快回来。但是从我关于列表的模糊信息来看,你不需要知道函数的每个细节。你的朋友想说的是,你需要维护一个连接列表。列表只是一个维护引用的对象
完成所有连接后,您可以浏览列表并“注销”或以其他方式断开与这些频道的连接。您的朋友想说的是,您需要维护一份连接列表。列表只是一个维护引用的对象
完成所有连接后,您可以浏览列表并“注销”或以其他方式断开与这些通道的连接。删除更合适。因为当你使用像 list.Clear()//这将清除整个列表 如果只是断开一个客户机的连接,则不希望删除所有客户机,只删除一个客户机 list.RemoveAt(int index)或list.Remove(Object o)只会从列表中删除特定的客户端 以下是一个可能有帮助的链接:
移除更合适。因为当你使用像 list.Clear()//这将清除整个列表 如果只是断开一个客户机的连接,则不希望删除所有客户机,只删除一个客户机 list.RemoveAt(int index)或list.Remove(Object o)只会从列表中删除特定的客户端 以下是一个可能有帮助的链接:
啊,好吧。在这种情况下,应该是相当容易的(一旦我了解了更多关于列表的内容…)和更有条理的。你知道什么更适合断开连接吗:删除还是清除?啊,好吧。在这种情况下,应该是相当容易的(一旦我了解了更多关于列表的内容…)和更有条理的。你知道什么更适合断开连接吗:删除还是清除?哈,每个人都在编辑。我似乎无法逃避那个游戏。哈,每个人都在编辑。我似乎无法逃避那场比赛。