C# 判断网络是否通的代码
2012-02-07 22:18 通用C#系统架构 阅读(1593) 评论(3) 编辑 收藏 举报 [DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int conn, int val);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int Out;
if (InternetGetConnectedState(out Out, 0) == true)
{
MessageBox.Show("Connected !");
}
else
{
MessageBox.Show("Not Connected !");
}
}
private extern static bool InternetGetConnectedState(out int conn, int val);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int Out;
if (InternetGetConnectedState(out Out, 0) == true)
{
MessageBox.Show("Connected !");
}
else
{
MessageBox.Show("Not Connected !");
}
}
判断邮箱地址是否有效的参考代码
private void button1_Click(object sender, EventArgs e)
{
string pattern = null;
pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
if (Regex.IsMatch("feedback@net-informations.com", pattern))
{
MessageBox.Show ("Valid Email address ");
}
else
{
MessageBox.Show("Not a valid Email address ");
}
}
{
string pattern = null;
pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
if (Regex.IsMatch("feedback@net-informations.com", pattern))
{
MessageBox.Show ("Valid Email address ");
}
else
{
MessageBox.Show("Not a valid Email address ");
}
}
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。