C# - 如何使用匿名方法返回值?

时间:2016-04-17 14:25:29

标签: c#

此代码失败:

    public bool generateNewIdentity()
    {
        TCPClient torIdentityClient = new TCPClient();

        torIdentityClient.OnConnect += delegate ()
        {
            torIdentityClient.Write("AUTHENTICATE \"*********************************\"\r\nSIGNAL NEWNYM\r\n");
        };

        torIdentityClient.OnRead += delegate (TCPClient tcpClient, string[] dataReadArray)
        {
            if(dataReadArray[0] == "250 OK")
            {
                return true;
            }
        };

        torIdentityClient.Delimiter = "\r\n";
        torIdentityClient.Connect("127.0.0.1", 9151);
    }

返回包含["250 OK", "250 OK"]

的字符串数组

它给我的例外是Anonymous function converted to a void returning delegate cannot return a value

我试图让它返回true,如果它得到250 OK。

如何解决此问题?

0 个答案:

没有答案