//需要的命名空间
using System.Runtime.InteropServices;
[DllImport("wininet.dll")]
//非托管调用API
private extern static bool InternetGetConnectedState( out int connectionDescription, int reservedValue ) ;
//实现方法 TRUE:连接 FALSE:未连接
private bool IsConnected()
{
int I=0;
bool state = InternetGetConnectedState(out I,0);
return state;
}