C#重写Restsharp旧版程序 [英] C# rewrite Restsharp old version program

查看:117
本文介绍了C#重写Restsharp旧版程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:

我发现了一些RestSharp代码,它是用.NET 4.5编写的,它似乎可以在一个网页上运行该程序。 现在我使用.NET 4.7.1和C#7.2,我使用的是Visual Studio 2017,但代码没有编译。 以下是代码:

I found some RestSharp Code, it was written in .NET 4.5 and it seems working on a web page hosts the program.  Now I am using .NET 4.7.1 with C# 7.2, I am using Visual Studio 2017, but the code is not compiled.  The following is the code:

namespace ConsoleApplication3
{
    using System;
    using System.Threading;

    using RestSharp;

    public class Program
    {
        public static async void Main()
        {
            var client = new RestClient();
            var request = new RestRequest("http://www.google.com");
            var cancellationTokenSource = new CancellationTokenSource();

            var restResponse = await client.ExecuteTaskAsync(request, cancellationTokenSource.Token);

            Console.WriteLine(restResponse.Content.Length);
        }
    }
}

编译器错误:

严重性 代码
描述 项目
文件
抑制状态

错误 CS5001
程序不包含适用于入口点的静态"Main"方法
ConsoleApplication3

Severity Code Description Project File Line Suppression State
Error CS5001 Program does not contain a static 'Main' method suitable for an entry point ConsoleApplication3

但是对于其原始的网络托管页面:  https://dotnetfiddle.net/tDtKbL

But for its original web hosting page: https://dotnetfiddle.net/tDtKbL

它好像它正在发挥作用。 我想知道如何将它移植到.NET Framework 4.7.1或4.7.2

It seems it is working.  I want to know how to port it to .NET Framework 4.7.1 or 4.7.2

它的语法似乎与我看到的大多数其他C#程序略有不同。

Its syntax seem to be a little different from what I see most of other C# programs.

谢谢,

PS:我用nuget来安装RestSharp: 

PS: I used nuget to install RestSharp: 

PM> Install-Package RestSharp -Version 106.3.1

PM> Install-Package RestSharp -Version 106.3.1

推荐答案

我没有机会尝试,但我认为缺少string [] args参数。
I don't have to chance to try it but I think string[] args parameter is missing.


这篇关于C#重写Restsharp旧版程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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