我有一個任務來創建一個類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