首先感谢所有人......
我目前正在研究VB。我正在使用Visual Studio 2008。
下面的代码是一个没有任何错误的构建控制台应用程序。
Imports System.Net
Module Module1
Public Sub Main()
Dim address As IPAddress
Dim remoteIP As System.Net.IPEndPoint
Dim socketAddress As System.Net.SocketAddress
Try
address = IPAddress.Parse("192.168.0.187")
remoteIP = New System.Net.IPEndPoint(address, 0)
socketAddress = remoteIP.Serialize()
Console.WriteLine("Address Family :" & remoteIP.AddressFamily.ToString())
Console.WriteLine("IP :" & remoteIP.Address.ToString() & "Port :" & remoteIP.Port.ToString())
Console.WriteLine("Socket address :" & socketAddress.ToString())
Catch ex As Exception
Console.WriteLine(ex.StackTrace.ToString())
End Try
End Sub
End Module
在下一个dll程序中,同样给出错误说“预期addr,remoteIP和socketAddr声明”
Imports System.Net
Public Class Class1
End Class
Public Class ethernet
Dim addr As IPAddress
Dim remoteIP As System.Net.IPEndPoint
Dim socketAddr As System.Net.SocketAddress
addr = IPAddress.Parse("192.168.0.187")
remoteIP = New System.Net.IPEndPoint(addr,0)
socketAddr = remoteIP.Serialize()
End Class
有人能告诉我为什么会这样吗......
答案 0 :(得分:1)
第二课ethernet
中的代码未包含在方法中,因此您只声明addr, remoteIP
和socketAddr
个变量。
为了完成这项工作,只需将代码放在一个方法中,例如:
Public Class ethernet
Public Function SerializeSocket(address As String) As System.Net.SocketAddress
Dim addr As IPAddress = IPAddress.Parse("192.168.0.187")
Dim remoteIP As System.Net.IPEndPoint = New System.Net.IPEndPoint(addr,0)
Return remoteIP.Serialize()
End Sub
End Class