我有一个任务来创建一个类Student
并创建一个方法,只有当他们的名字在他们的姓氏之前按字母顺序使用LINQ查询操作符从数组中挑选学生。我已经写了Student
类:无法隐式转换类型错误
public class Student
{
private string firstName;
private string familyName;
private int age;
public Student(string firstName, string familyName, int age)
: this()
{
this.firstName = firstName;
this.familyName = familyName;
this.age = age;
}
public Student()
{
firstName = "Dancho";
familyName = "Mastikata";
age = 24;
this.firstName = firstName;
this.familyName = familyName;
this.age = age;
}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string FamilyName
{
get { return familyName; }
set { familyName = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
然后我编码这一个:
public class StudentsManipulations
{
static void Main()
{
Student[] students = new Student[6]{new Student("Georgi", "Milanov", 21 ),
new Student("Ilko", "Pirgov", 30 ),
new Student("Neboisha", "Yelenkovich", 34),
new Student("Dimitar", "Berbatov", 32 ),
new Student( ),
new Student("Nikolai", "Bodurov", 24 )};
}
public static List<Student> StudentSortByFirstName(Student[] students)
{
List<Student> sortedStudents = from student in students
where student.FirstName.CompareTo(student.FamilyName) < 0
select student;
return sortedStudents;
}
}
不幸的是,在关键字的错误,我不能完全理解:
无法将类型 'System.Collections.Generic.IEnumerable'隐式转换为 'System.Collections.Generic.List'。存在明确转换 (您是否缺少演员?)。
你能帮我理解究竟是什么错误吗?
我喜欢你的伟大的BG足球运动员名单:) – EkoostikMartin 2013-03-12 13:29:59
感谢您的帮助 - 每个人! – 2013-03-12 16:45:32