【问题标题】:Overload error when adding objects to list将对象添加到列表时出现重载错误
【发布时间】:2015-11-26 06:19:38
【问题描述】:

我编写了一个 Web 服务和构造函数,可以将对象添加到我的列表中。我收到一个对我来说毫无意义的错误,因为我传入了我应该传入的 3 个参数。

错误是:

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

这是我的代码:

网络服务:

[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;
    }
}

我正在使用网络服务的项目

 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)....

【问题讨论】:

  • GetTileArticleDetails 中似乎多了一个逗号。
  • @jstreet 多余的逗号在哪里?
  • string ,myTitleView 多了一个逗号。
  • 如果您想将其发布为解决方案,我会将其标记为已回答@jstreet

标签: c# .net list web-services wcf


【解决方案1】:

替换这一行:

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));

请注意,) 紧跟在 " ...") 之后。

【讨论】:

    猜你喜欢
    • 2018-06-02
    • 2021-07-29
    • 1970-01-01
    • 2023-01-13
    • 2012-01-25
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多