没有静态字段,无法从另一个类调用方法

时间:2019-01-16 07:04:53

标签: c# .net interface

我有此代码的界面

interface IHttpRequest
{
    Task<string> GetCountries();
}

我在这样的课堂上继承

public class GettingCountries: IHttpRequest
{
    public async Task<string> GetCountries()
    {
        var client = new RestClient("http://api.xplorpal.com");
        var request = new RestRequest("/countries", Method.POST);
        var response = await client.ExecuteTaskAsync(request);
        var content = response.Content;
        var responseCountries = JsonConvert.DeserializeObject<IEnumerable<GettingCountry.RootObjectCountries>>(content);

        GettingCountry.CountriesList.Clear();
        GettingCountry.ListOfCountriesRoot.Clear();

        foreach (var country in responseCountries)
        {
            GettingCountry.CountriesList.Add(country.nicename);
            GettingCountry.ListOfCountriesRoot.Add(new GettingCountry.RootObjectCountries(country.id, country.nicename));
        }
        return content;
    }


}

此后,我需要在某个地方调用此类的方法,例如var countries_list = await GettingCountries.GetCountries();

但是现在我有错误。

enter image description here

我该如何解决?我可以将其设置为静态,但是可以吗?也许还有其他吗?

0 个答案:

没有答案