【发布时间】:2013-09-24 23:18:55
【问题描述】:
我的代码:
public ChatServer()
{
//create our nickname and nickname by connection variables
nickName = new Hashtable(100);
nickNameByConnect = new Hashtable(100);
//create our TCPListener object
chatServer = new System.Net.Sockets.TcpListener(4296);
//check to see if the server is running
//while (true) do the commands
while (true)
{
chatServer.Start();
if (chatServer.Pending())
{
Chat.Sockets.TcpClient chatConnection = chatServer.AcceptTcpClient();
Console.WriteLine("You Are Connected");
DoCommunicate com = new DoCommunicate(chatConnection);
}
}
}
public static void SendMsgToAll(string nick, string msg)
{
StreamWriter writer;
ArrayList remove = new ArrayList(0);
Chat.Sockets.TcpClient[] tcpClient = new Chat.Sockets.TcpClient[ChatServer.nickName.Count];
ChatServer.nickName.Values.CopyTo(tcpClient, 0);
从我上面的代码中,我们可以看到有 2 种方法 i- ChatServer ii- SendMsgToAll。
所以当我尝试在第二种方法中写Chat.Sockets.TcpClient[] tcpClient = new Chat.Sockets.TcpClient[ChatServer.nickName.Count];行时
它给出了以下错误:
ChatSerevr() 是在给定上下文中无效的方法。
我用谷歌搜索但找不到正确的解决方案。提前致谢
【问题讨论】:
-
ChatSerevr()!=CharServer()错字还是? -
我不清楚你的评论。你能详细说明一下吗?
-
编译器抛出该错误的行在哪里?