简体   繁体   English

无法将类型接口隐式转换为&#39;System.Collections.Generic.IList <T> &#39;

[英]Cannot implicitly convert type Interface to 'System.Collections.Generic.IList<T>'

stuck in below issue please help, I have one below class and it contain one method with return type is interface 卡在下面的问题中,请帮忙,我有一个下面的类,它包含一个返回类型为接口的方法

public class Helper
{ 
    public IRestResponse GetCam (string searchTerm, int page, int pageSize)
    {
       RestRequest request = new RestRequest(Method.GET)
                             {
                               RequestFormat = DataFormat.Json,
                               Resource = string.Format("/assets/campaigns?search={0}&page={1}&count={2}&depth=complete",
                               searchTerm, page, pageSize)
                              };

      IRestResponse response = _client.Execute(request);

      return response;
    }
}

in that interface I have some get set, 在该界面中,我有一些设置,

public interface IRestResponse
    {
        string Content { get; set; }
        string ContentEncoding { get; set; }
        long ContentLength { get; set; }
        string ContentType { get; set; }
        IList<RestResponseCookie> Cookies { get; }
        Exception ErrorException { get; set; }
        string ErrorMessage { get; set; }
        IList<Parameter> Headers { get; }
        IRestRequest Request { get; set; }
        ResponseStatus ResponseStatus { get; set; }
        Uri ResponseUri { get; set; }

    }
}

Now when I call Helper class in my another program like below it giving me error as : 现在,当我在下面的另一个程序中调用Helper类时,出现以下错误:

"Cannot implicitly convert type 'RestSharp.IRestResponse' to 'System.Collections.Generic.IList>'. An explicit conversion exists (are you missing a cast?)" “无法将类型'RestSharp.IRestResponse'隐式转换为'System.Collections.Generic.IList>'。存在显式转换(是否缺少转换?)”

my calling program have below code 我的调用程序有以下代码

CamSample.Helper f = new CampaignHelper("Company name", "UserName", "Password", "SiteName");
IList<CampaignSample.Models.IRestResponse> q = new List<CampaignSample.Models.IRestResponse>();
//List<IRestResponse<CampaignSample.Models.Campaign>> w = new IList<IRestResponse<CampaignSample.Models.Campaign>>().ToList();
q = f.GetCam("", 1, 200);

--- getting the error here Please tell me the solution ---这里出现错误请告诉我解决方案

Your method is returning IResponse object not List<IResponse> object, you shoud be writing like this when calling: 您的方法返回的是IResponse对象而不是List<IResponse>对象,调用时应这样编写:

CampaignSample.Models.IRestResponse response = f.GetCam("", 1, 200);

or you can make use of var here: 或者您可以在这里使用var

var response = f.GetCam("", 1, 200);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法隐式转换类型System.Collections.Generic.IList System.Collections.Generic.List - Cannot implicitly convert type System.Collections.Generic.IList System.Collections.Generic.List 无法将类型&#39;System.Collections.Generic.List &lt;&gt;&#39;隐式转换为&#39;System.Collections.Generic.IList &lt;&gt;&#39; - Cannot implicitly convert type 'System.Collections.Generic.List< >' to 'System.Collections.Generic.IList< >' 无法隐式转换类型&#39;System.Collections.Generic.List <AnonymousType#1> &#39;到&#39;System.Collections.Generic.IList - Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.IList 无法将类型“System.Linq.IQueryable”隐式转换为“System.Collections.Generic.IList” - Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList' 无法将类型&#39;ListName []&#39;隐式转换为&#39;System.Collections.Generic.IList <ListName> “ - Cannot implicitly convert type 'ListName[]' to 'System.Collections.Generic.IList<ListName>' 无法将类型&#39;...&#39;隐式转换为&#39;System.Collections.Generic.IList &lt;...&gt;&#39;。 存在显式转换(您是否错过了演员?) - Cannot implicitly convert type '…' to 'System.Collections.Generic.IList<…>'. An explicit conversion exists (are you missing a cast?) 无法将类型&#39;ServiceReference1.Videos []&#39;隐式转换为&#39;System.Collections.Generic.IList <Videos> - Cannot implicitly convert type 'ServiceReference1.Videos[]' to 'System.Collections.Generic.IList<Videos> 无法将类型“字符串”转换为“System.Collections.Generic.IList”<string></string> - Cannot convert type 'string' to 'System.Collections.Generic.IList<string> 无法巧妙地将类型Void转换为类型System.Collections.Generic.IList <T> - Cannot Implicityly Convert Type Void To Type System.Collections.Generic.IList<T> Cannot convert type 'System.Collections.Generic.List&lt; &gt;' to 'System.Collections.Generic.IList&lt; &gt;' c# MongoDB - Cannot convert type 'System.Collections.Generic.List< >' to 'System.Collections.Generic.IList< >' c# MongoDB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM