读书人

VB.NET里的嘱托

发布时间: 2013-04-21 21:18:07 作者: rapoo

VB.NET里的委托
一段C#代码想成VB.NET时,却有错误
C#代码ShowMsg.cs里只有一句

public delegate void ShowMsg(string strMsg);

类Connection.cs里

public class Connection
{
string strPath;
ShowMsg showMsg;
ShowMsg removeConnection;
Thread threadMsg;
bool isWait = true;
...
public Connection(string strPath, ShowMsg showMsg, ShowMsg removeConnection)
{
...
this.strPath = strPath;
this.showMsg = showMsg;
this.removeConnection = removeConnection;

this.threadMsg = new Thread(WaitMsg);
this.threadMsg.IsBackground = true;
this.threadMsg.Start();
...
}

void WaitMsg()
{
while (isWait)
{
try
{
...
showMsg(strMsg);
}
catch (Exception ex)
{
...
removeConnection(strMsg);
}
}
}
...


上述代码改成VB.NET后,WaitMsg里的showMsg(strMsg)和removeConnection(strMsg)这两句,都提示错误“表达式不是方法”,为什么?应该怎么改才正确,谢谢。
VB.net?委托 vb.net ,委托? 委托
[解决办法]
Public Class ShowMsg
Public Delegate Sub ShowMsg(ByVal strMsg As String)
End Class


去掉Public Class ShowMsg 和 End Class

读书人网 >VB Dotnet

热点推荐