Webclient.DownloadFile 类、结构或接口成员声明中的标记“(”无效

本文关键字:无效 声明 DownloadFile 结构 成员 接口 Webclient | 更新日期: 2023-09-27 17:56:51

我正在尝试从 https://webgis.dme.qld.gov.au/webgis/webqmin/shapes/epm.tar 下载文件以保存到我的d:''使用网络客户端的驱动器。我收到错误类、结构或接口成员声明中的标记"("无效就在"客户端.下载文件"之后

这是我第一次使用 C#!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project1
{
    class Class1
    {
        WebClient Client = new WebClient ();
        Client.DownloadFile("https://webgis.dme.qld.gov.au/webgis/webqmin/shapes/epm.tar", @"d:'epm.tar");
     }
}

Webclient.DownloadFile 类、结构或接口成员声明中的标记“(”无效

你需要把你的代码放到一个方法中:

namespace Project1
{
  class Class1
  {
    public void DownloadIt()
    {
        WebClient Client = new WebClient ();
        Client.DownloadFile("https://webgis.dme.qld.gov.au/webgis/webqmin/shapes/epm.tar",      @"d:'epm.tar");
    }
  }
}

然后,要使用它,只需从控制台应用或 winform 应用调用该方法:

Class1 c = new Class1();
c.DownloadIt();