从public static double中获取字符串 [英] get string from public static double
本文介绍了从public static double中获取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家希望你们结束快乐的一年..
i有问题,如果可以请你放手......
即时通讯使用Windows应用程序查看连接雕像
它给结果e带(100,60 ,,,或0)
但我想如果totoaltime = 0它显示字符串给出一些文字
hi everyone wish happy ending year for you guys..
i have question if you could please give hand...
im using windows application for checking connection statues
it give the result e with either (100,60,,, or 0)
but i want if totoaltime=0 it show string give some text
private void buttonX1_Click(object sender, EventArgs e)
{
richTextBox1.Text += "return is ={"+(pingcheck(Ipinput1.Text,Convert.ToInt32(Txpackage1.Text)))+"}"+Environment.NewLine;
richTextBox2.Text +=" return is={"+(pingcheck(Ipinput2.Text, Convert.ToInt32(Txtpackag2.Text)))+"}" + Environment.NewLine;
}
public static double pingcheck(string host, int echonum)//i tried with (string host, int echonum,string getipstatues) but it won't retrieve
{
long totaltime = 0;
int timeout = 120;
Ping pingsender = new Ping();
for (int i = 0; i < echonum; i++)
{
PingReply replay = pingsender.Send(host, timeout);
if (replay.Status == IPStatus.Success)
{
totaltime += replay.RoundtripTime;
}
else if(totaltime==0)
{
//messagebox.show("your connection is not available "); here it will show every time when totaltime =0
string getipstatue = "the connectin is not available ";//but i wanna show this this text not messagebox
}
}
return totaltime + echonum;
}
推荐答案
RoundTripTime
属性和你的totaltime
不是double
值 - 它们很长,这意味着int64 - 所以CHill60说,你可以直接把它比作0没有任何问题:
TheRoundTripTime
property and yourtotaltime
aren'tdouble
values - they are long, which means int64 - so as CHill60 says, you can compare it directly to 0 without any problems:
else if(totaltime == 0)
但是设置字符串不会显示任何内容。所以尝试
But just setting a string doesn't display anything. So try
}
else if(totaltime == 0)
{
MessageBox.Show("The connection is not available ");
}
这里我得到了解决方案,如果有人知道它...谢谢你多了
here i got solution if someone neet id it... thanks for you sou much
public static bool PingCheck(string host, int echonum, out double approximateTime)
{
long totaltime = 0;
int timeout = 120;
Ping pingsender = new Ping();
for (int i = 0; i < echonum; i++)
{
PingReply replay = pingsender.Send(host, timeout);
if (replay.Status == IPStatus.Success)
{
totaltime += replay.RoundtripTime;
}
else
{
approximateTime = 0.0;
return false;
}
}
approximateTime = (double)totaltime / echonum;
return true;
}
private void buttonX1_Click(object sender, EventArgs e)
{
double appTime;
if (PingCheck("8.8.8.", 1, out appTime))
{
richTextBox1.Text += appTime.ToString("F2") + Environment.NewLine;
} else {
richTextBox1.Text += "the connectin is not available";
}
}
这篇关于从public static double中获取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文