我在下面的代码中收到一个错误,它说我无法将方法组 ListStudents 转换为 generic.list,如果我在 ListStudents 末尾尝试 () 我得到:无法将数组转换为列表
我想做的就是将一些用户硬编码到一个数组中并在我的 GET 请求中返回它们是否有解决方法?
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "")]
List<Student> GetStudentCollection();
}
[DataContract(Name="Student")]
public class Student
{
[DataMember(Name = "StudentID")]
public string StudentID { get; set; }
[DataMember(Name = "FirstName")]
public string FirstName { get; set; }
[DataMember(Name = "LastName")]
public string LastName { get; set; }
}
public class RawDataService : IReceiveData
{
public Student[] ListStudents()
{
List<Student> student = new List<Student>()
{
new Student { StudentID="bla", FirstName="bla", LastName="bla"},
new Student { StudentID="bla1", FirstName="bla1", LastName="bla1"},
new Student { StudentID="bla2", FirstName="bla2", LastName="bla2"}
};
return student.ToArray();
}
public List<Student> GetStudentCollection()
{
return ListStudents(); //error on this line, cant convert array to list
}