将对象添加到列表时发生重载错误

本文关键字:重载 错误 列表 对象 添加 | 更新日期: 2023-09-27 18:24:21

我已经编写了一个web服务和构造函数,它将对象添加到我的列表中。我得到了一个对我来说毫无意义的错误,因为我正在传递我应该传递的3个参数。

错误为:

没有给出与所需形式相对应的自变量的参数"myArticleID"'MainPage.GetTileDetails.GetTileDetails(string,string,int)'

这是我的代码:

Web服务:

[OperationContract]
List<ViewDetails> ViewDetails();
[DataContract]
public class ViewDetails
{
    [DataMember]
    public string TitleView { get; set; }
    [DataMember]
    public string BodyView { get; set; }
    [DataMember]
    public int ArticleID { get; set; }
    public ViewDetails() { }
    public ViewDetails(string myTitleView, string myBodyView, int myArticleID)
    {
        this.TitleView = myTitleView;
        this.BodyView = myBodyView;
        this.ArticleID = myArticleID;
    }
}

我使用web服务的项目

 public async void ViewData()
    {
        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
        List<GetTileDetails> tileList = new List<GetTileDetails>();
        var res = await client.ViewDetailsAsync();
        for (int i = 0; i < res.Count; i++)
        {
            tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ..."), res[i].ArticleID);
        }
        tileGridView.ItemsSource = tileList;
    }
public class GetTileDetails
    {
        public string TitleView { get; set; }
        public string BodyView { get; set; }
        public int ArticleID { get; set; }
        public GetTileDetails() { }
        public GetTileDetails(string myTitleView, string myBodyView, int myArticleID)
        {
            this.TitleView = myTitleView;
            this.BodyView = myBodyView;
            this.ArticleID = myArticleID;
        }
    }

有人能告诉我为什么会犯那个错误吗?我正在传入(string,string,int)。。。。

将对象添加到列表时发生重载错误

替换此行:

tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ..."), res[i].ArticleID);

这个:

tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ...", res[i].ArticleID));

请注意,在" ...")之后有一个放错地方的)