0

我的代码:

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() 是在给定上下文中无效的方法

我用谷歌搜索,但找不到正确的解决方案。提前致谢

4

2 回答 2

3

重命名ChatServer()方法或重命名ChatServer类型(或属性)。编译器认为,您在这里使用了一种方法:ChatServer.nickName.Count.

于 2013-06-03T09:31:56.020 回答
-1

我可能有点晚了...

请确保您没有与您的类同名的方法(构造函数当然不适用)

于 2013-09-24T15:18:55.337 回答