开发者

VB.NET object initialization not working?

OK, this probably is going to be a head-banger, but why is this code not working?

Dim tcplistener As New System.Net.Sockets.TcpListener

This does not compile with the error "Overload resolution failed because no accessible 'New' accepts this number of arguments."

The thing is, I have to 开发者_C百科declare it as New because otherwise I will get a null-reference exception...

Does anybody know what I am doing wrong, or should do differently?

Thanks!


Look at the constructor overloads available. They all have parameters - so you can't just create a TcpListener without any arguments. What port do you want to listen to, for example?

You might want something like:

Dim tcplistener As New System.Net.Sockets.TcpListener(8080)

which should work fine.

This isn't specific to TcpListener - you should always consider which arguments you want to pass to a constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜