using System; using System.Collections.Generic; using System.Linq; using System.Text; class StudentInfo { public StudentInfo(string ln, string fn, int id, string a) { lastName = ln; firstName = fn; idNumber = id; address = a; } public override string ToString() { return firstName + " " + lastName + " " + idNumber + " " + address; } public string FirstName { get { return firstName; } set { firstName = value; } } public string LastName { get { return lastName; } set { lastName = value; } } public string Address { get { return address; } set { address = value; } } public int ID { get { return idNumber; } set { idNumber = value; } } private string firstName; private String lastName; private int idNumber; private string address; } public class LINQtoList { static void Main(string[] args) { StudentInfo[] students ={ new StudentInfo("Smith", "John", 12345, "5 Bournbrook Rd"), new StudentInfo("Brown", "Alan", 23412, "Dawlish Rd"), new StudentInfo("Smith","Colin", 41253, "23 Bristol Rd"), new StudentInfo("Hughes", "Richard", 52314, "18 Prichatts Rd"), new StudentInfo("Murphy", "Paul", 16352, "37 College Rd") }; List studentList = new List(); studentList.Add(students[0]); studentList.Add(students[1]); studentList.Add(students[2]); studentList.Insert(2, students[3]); //PrintList(studentList, "Student list:"); var orderedUpperCaseList = from student in studentList let upperCaseName = student.LastName.ToUpper() orderby upperCaseName select upperCaseName; PrintList(orderedUpperCaseList, "Ordered student list:"); } public static void PrintList(IEnumerable arr, string message) { Console.WriteLine("{0}", message); foreach (T element in arr) Console.WriteLine(" {0}", element); Console.WriteLine(); } }