【问题标题】:insert data to list in WCF将数据插入 WCF 中的列表
【发布时间】:2016-05-10 07:26:06
【问题描述】:

我有一个包含 Student 类的 WCF,并且只返回一个双(平均)变量:

public  class Student
{
    public String Name { set; get; }
    public String Family { set; get; }
    public List<double> GradeList { get;   
}

我在我的项目中插入了这个 WCF 现在我可以将数据插入到学生姓名和家庭,但我不能将项目插入到 GradeList 列表中。 像这样:

Student ss = new Student();
ss.Name = txtname.Text;
ss.Family = txtFamily.Text;
// insert from listbox to list
foreach (double strCol in lstGrade.Items)
{
    ss.GradeList.add(strCol);
}

但是 "add" 会出错。 谁能帮帮我?

【问题讨论】:

  • 您可以添加错误的副本吗?你的班级也很奇怪:GradeList { get; 你忘了完成复制行吗?

标签: c# wcf-data-services


【解决方案1】:

如果 GradeList 有一个集合,则需要确保已初始化该属性。

修复

     ss.GradeList = new List<double>();

完整代码如下

Student ss = new Student();
ss.Name = txtname.Text;
ss.Family = txtFamily.Text;
// insert from listbox to list
 ss.GradeList = new List<double>();

foreach (double strCol in lstGrade.Items)
{


 ss.GradeList.add(strCol);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    相关资源
    最近更新 更多