我想将此控制台代码转换为表单代码:
public void catching(string[] args)
{
UdpClient udpc = new UdpClient(args[0], 2055);
IPEndPoint ep = null;
while (true)
{
Console.Write("Name: ");
string name = Console.ReadLine();
if (name == "") break;
byte[] sdata = Encoding.ASCII.GetBytes(name);
udpc.Send(sdata, sdata.Length);
byte[] rdata = udpc.Receive(ref ep);
string job = Encoding.ASCII.GetString(rdata);
Console.WriteLine(job);
}
}
我想把它放到一个按钮click
事件中:
private void button1_Click(object sender, EventArgs e)
{
}
但我收到这条线的错误:
UdpClient udpc = new UdpClient(args[0], 2055);