I get an error in the bellow code it says I cannot convert method group ListStudents to generic.list, if I try () at the end of ListStudents I get: cant convert array to list
All im trying to do is hardcode some users to an array and return them in my GET request is there a fix for this?
[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
}
Try using the
ToListlinq extension method:However, to reduce the number of conversions I would suggest changing the methods as follows: