抛出IMAP C#异常

时间:2017-12-14 01:53:40

标签: c# imap

我尝试使用C#实现IMAP。

我有以下功能:

public int MailUnreadCount()
    {
        imapSw.WriteLine("$ STATUS INBOX (unseen)");
        imapSw.Flush();

        string res = Response();
        Match m = Regex.Match(res, "[0-9]*[0-9]");
        return Convert.ToInt32(m.ToString());
    }

然后我上线了:

return Convert.ToInt32(m.ToString());

以下错误说明:

Exception thrown: 'System.FormatException' in mscorlib.dll

任何人都知道这是什么问题?

感谢。

1 个答案:

答案 0 :(得分:0)

你应该使用:

Match m = Regex.Match(res, "[0-9]*[0-9]");
if (m.Success)
{
    return Convert.ToInt32(m.Value);
}