C# 判断网络是否通的代码

2012-02-07 22:18        by         通用信息化建设平台,         1021         阅读,         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 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( " [email protected] ", pattern))
           {
               MessageBox.Show ( " Valid Email address ");
           }
else
           {
               MessageBox.Show( " Not a valid Email address ");
           }
       }
复制代码





你可能感兴趣的:(网络,信息化,public)