Ping 和一般结构 C# - Visual Studio 2010
首先让我概述一下我的申请。我正在尝试使用 Visual C# 对用户指定的地址执行 PING。用户通过在文本框中输入他们想要 PING 的地址来与系统交互 - 然后用户单击 ping 按钮,该按钮将 ping 所需的地址,然后通过消息框将结果返回给用户。
这只是应用程序的初始阶段。
我对以下代码有问题:
using System;
using System.Collections.Generic;
using System.Net;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace Ping_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pingButton_Click(object sender, EventArgs e)
{
int timeOut = 300;
int ttl = 300;
string stat = "", data = "[012345678901234567890123456789]";
PingOptions pingOpts = new PingOptions();
pingOpts.Ttl = ttl;
pingOpts.DontFragment = true;
Ping pinger = new Ping();
PingReply reply = pinger.Send(pingAddressTextBox.Equals, timeOut, Buffer, pingOpts);
if (reply.Status.ToString() != "Success")
stat = "Failed";
else
stat = reply.Status.ToString();
pinger.Dispose();
MessageBox.Show("Congratulations!");
}
}
}
此代码来自有关堆栈溢出的另一个主题 - 我试图通过使代码正常工作然后修改它来获得理解。
错误是:
错误 1“System.Buffer”是“类型”,但像“变量”一样使用 错误 3 参数 1:无法从“方法组”转换为“System.Net.IPAddress”
错误 4 参数 3:无法从“System.Buffer”转换为“byte[]” 错误 2 'System.Net.NetworkInformation.Ping.Send(System.Net.IPAddress, int, byte[], System.Net.NetworkInformation.PingOptions)' 的最佳重载方法匹配有一些无效 正如我所说,
我只是在学习 - 这只是为了开怀大笑 - 任何帮助表示赞赏。
Initially let me give an overview of my application. I am attempting to use Visual C# to do a PING on an address the user specifies. The user interacts with the system by entering the address they wish to PING into the textbox - the user then clicks the pingButton which will ping the desired address and then return the results to the user via a message box.
This is just the initial stage of the application.
I am having problem with the following code:
using System;
using System.Collections.Generic;
using System.Net;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace Ping_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pingButton_Click(object sender, EventArgs e)
{
int timeOut = 300;
int ttl = 300;
string stat = "", data = "[012345678901234567890123456789]";
PingOptions pingOpts = new PingOptions();
pingOpts.Ttl = ttl;
pingOpts.DontFragment = true;
Ping pinger = new Ping();
PingReply reply = pinger.Send(pingAddressTextBox.Equals, timeOut, Buffer, pingOpts);
if (reply.Status.ToString() != "Success")
stat = "Failed";
else
stat = reply.Status.ToString();
pinger.Dispose();
MessageBox.Show("Congratulations!");
}
}
}
This code is from another topic on stack overflow - I am trying to gain an understanding by getting the code working and then modifying it.
The errors are:
Error 1 'System.Buffer' is a 'type' but is used like a 'variable'
Error 3 Argument 1: cannot convert from 'method group' to 'System.Net.IPAddress'
Error 4 Argument 3: cannot convert from 'System.Buffer'to 'byte[]'
Error 2 The best overloaded method match for 'System.Net.NetworkInformation.Ping.Send(System.Net.IPAddress, int, byte[], System.Net.NetworkInformation.PingOptions)' has some invalid
arguments
As I say I am just learning - this is just for a bit of a laugh - any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个
Buffer
类型的对象来传递给pinger.Send
。这里你只有类型名称。您需要一个实际的
byte
数组:源
这里
buffer
是从字符串创建的。你错过了这一步。You need an object of type
Buffer
to pass topinger.Send
.Here you just have the type name. You need an actual
byte
array:Source
Here
buffer
is created from the string. You're missing this step.