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
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 ...
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ìm kiếm theo từ khóa liên quan:
giáo trình đại học tài liệu mạng giáo trình cơ điện giáo trình thiết kế tài liệu kế toánTài liệu liên quan:
-
Giáo trình phân tích một số loại nghiệp vụ mới trong kinh doanh ngân hàng quản lý ngân quỹ p5
7 trang 474 0 0 -
MARKETING VÀ QUÁ TRÌNH KIỂM TRA THỰC HIỆN MARKETING
6 trang 303 0 0 -
122 trang 217 0 0
-
QUY CHẾ THU THẬP, CẬP NHẬT SỬ DỤNG CƠ SỞ DỮ LIỆU DANH MỤC HÀNG HÓA BIỂU THUẾ
15 trang 213 1 0 -
BÀI GIẢNG KINH TẾ CHÍNH TRỊ MÁC - LÊNIN - TS. NGUYỄN VĂN LỊCH - 5
23 trang 210 0 0 -
Giáo trình hướng dẫn phân tích các thao tác cơ bản trong computer management p6
5 trang 201 0 0 -
Giáo trình chứng khoán cổ phiếu và thị trường (Hà Hưng Quốc Ph. D.) - 4
41 trang 200 0 0 -
HỌC VIỆN CÔNG NGHỆ BƯU CHÍNH VIỄN THÔNG - NGÂN HÀNG ĐỀ THI HẾT HỌC PHẦN HỌC PHẦN: TOÁN KINH TẾ
9 trang 177 0 0 -
BÀI GIẢNG LÝ THUYẾT MẠCH THS. NGUYỄN QUỐC DINH - 1
30 trang 176 0 0 -
Giáo trình phân tích giai đoạn tăng lãi suất và giá trị của tiền tệ theo thời gian tích lũy p10
5 trang 170 0 0