Danh mục

Giáo trình phân tích cấu tạo bo mạch mảng một chiều các giá trị bên trong dấu ngoặc p8

Số trang: 5      Loại file: pdf      Dung lượng: 901.50 KB      Lượt xem: 6      Lượt tải: 0    
Thư viện của tui

Hỗ trợ phí lưu trữ khi tải xuống: miễn phí Tải xuống file đầy đủ (5 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu giáo trình phân tích cấu tạo bo mạch mảng một chiều các giá trị bên trong dấu ngoặc p8, kỹ thuật - công nghệ, điện - điện tử phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Giáo trình phân tích cấu tạo bo mạch mảng một chiều các giá trị bên trong dấu ngoặc p8. Ngôn Ngữ Lập Trình C# // phương thức tĩnh để nhận đối tượng Comparer public static EmployeeComparer GetComparer() { return new Employee.EmployeeComparer(); } public int CompareTo(Object rhs) { Employee r = (Employee) rhs; return this.empID.CompareTo(r.empID); } // thực thi đặc biệt được gọi bởi custom comparer public int CompareTo(Employee rhs, Employee.EmployeeComparer.ComparisionType which) { switch (which) { case Employee.EmployeeComparer.ComparisionType.EmpID: return this.empID.CompareTo( rhs.empID); case Employee.EmployeeComparer.ComparisionType.Yrs: return this.yearsOfSvc.CompareTo( rhs.yearsOfSvc); } return 0; } // lớp bên trong thực thi IComparer public class EmployeeComparer : IComparer { // định nghĩa kiểu liệt kê public enum ComparisionType { EmpID, Yrs }; // yêu cầu những đối tượng Employee tự so sánh với nhau public int Compare( object lhs, object rhs) { Employee l = (Employee) lhs; Employee r = (Employee) rhs; return l.CompareTo(r, WhichComparision); 258. Mảng, Chỉ Mục, và Tập Hợp Ngôn Ngữ Lập Trình C#. } public Employee.EmployeeComparer.ComparisionType WhichComparision { get { return whichComparision; } set { whichComparision = value; } } private Employee.EmployeeComparer.ComparisionType whichComparision; } private int empID; private int yearsOfSvc = 1; } public class Teser { static void Main() { ArrayList empArray = new ArrayList(); Random r = new Random(); // đưa vào mảng for(int i=0; i < 5; i++) { empArray.Add( new Employee(r.Next(10)+100, r.Next(20))); } // hiển thị tất cả nội dung của mảng Employee for(int i=0; i < empArray.Count; i++) { Console.Write(“ {0} ”, empArray[i].ToString()); } Console.WriteLine(“ ”); // sắp xếp và hiển thị mảng Employee.EmployeeComparer c = Employee.GetComparer(); c.WhichComparision = Employee.EmployeeComparer.ComparisionType.EmpID; 259 . Mảng, Chỉ Mục, và Tập Hợp. Ngôn Ngữ Lập Trình C# empArray.Sort(c); // hiển thị nội dung của mảng for(int i=0; i < empArray.Count; i++) { Console.Write(“ {0} ”, empArray[i].ToString()); } Console.WriteLine(“ ”); c.WhichComparision = Employee.EmployeeComparer.ComparisionType.Yrs; empArray.Sort(c); // hiển thị nội dung của mảng for(int i=0; i < empArray.Count; i++) { Console.Write(“ {0} ”, empArray[i].ToString()); } Console.WriteLine(“ ”); } } } -----------------------------------------------------------------------------  Kết quả: ID: 100. Years of Svc: 16 ID: 102. Years of Svc: 8 ID: 107. Years of Svc: 17 ID: 105. Years of Svc: 0 ID: 101. Years of Svc: 3 ID: 100. Years of Svc: 16 ID: 101. Years of Svc: 3 ID: 102. Years of Svc: 8 ID: 105. Years of Svc: 0 ID: 107. Years of Svc: 17 ID: 105. Years of Svc: 0 ID: 101. Years of Svc: 3 ID: 102. Years of Svc: 8 ID: 100. Years of Svc: 16 ID: 107. Years of Svc: 17 ----------------------------------------------------------------------------- 260. Mảng, Chỉ Mục, và Tập Hợp. Ngôn ...

Tài liệu được xem nhiều: