[英]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.