检查互联网连接 [英] Check Internet connection

查看:91
本文介绍了检查互联网连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此示例来检查计算机是否已连接到Internet,但它给我3个错误.为什么这样?

这里是示例:

I'' m using this sample to check if the machine is connected to Internet, but it gives me 3 errors. Why'' s that?

Here is the sample:

<br />using System;<br />using System.Runtime;<br />using System.Runtime.InteropServices;<br /><br />class IsConnected<br />{<br />    //Creating the extern function...<br />    [DllImport("wininet.dll")]<br />    private extern static bool InternetGetConnectedState(int out Description, int ReservedValue);<br /><br />    //Creating a function that uses the API function...<br />    public static bool IsConnectedToInternet()<br />    {<br />        int Desc;<br /><br />        return InternetGetConnectedState(out Desc, 0);<br />    }<br />}<br />



这里是错误:



Here are the errors:

<br />Error 1: Identifier expected; ''out'' is a keyword | Line: 9<br />Error 2: Invalid token '','' in class, struct, or interface member declaration | Line: 9<br />Error 3: ; expected | Line: 9<br />





推荐答案

我猜你必须写InternetGetConnectedState(out int Description, ....

I guess you have to write InternetGetConnectedState(out int Description, ....


更改为此行...

change to this line...

private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);






这篇关于检查互联网连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆