Đang chuẩn bị liên kết để tải về tài liệu:
Bài giảng C# và môi trường Donet - Bài 12: Generic và Iterator

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Nội dung trình bày trong bài 12 gồm có: Generic là gì? System Collections Generic namespace, Icomparable và Icomparer Interface, generic class, generic method, generic interface, iterator là gì? tạo iterator. . | Bài 12 Generic và Iterator Ôn tập lại bài cũ Khái niệm Collection System.Collection namespace ArrayList Hashtable SortedList Dictionary Stack Queue LinkedList Subject name / Session# / of Totalpage Nội dung trình bày Generic là gì? System.Collections.Generic namespace Icomparable và Icomparer Interface Generic class Generic method Generic interface Iterator là gì? Tạo iterator Generic and Iterator Vấn đề của generalized class và sự ra đời của kỹ thuật Generic? using System.Collections; ArrayList myList = new ArrayList(); Employee myEmp = new Employee(); myList.Add(myEmp); myEmp = (Employee)myList[0]; ArrayList myList = new ArrayList(); int myInt = 99; myList.Add(myInt); // box the int to an object myInt = (int)myList.[0]; // unbox the object to an int Generic and Iterator Vấn đề của generalized class và sự ra đời của kỹ thuật Generic? Các lớp trong System.Collection namespace là các generalized classes Khi sử dụng, chúng ta luôn phải ép kiểu(cast), chương trình luôn phải thực hiện thao tác box và unbox khi thực thi, do đó chiếm nhiều bộ nhớ và thời gian của CPU. Kỹ thuật generic đã ra đời trong phiên bản C# 2.0 để khắc phục những nhược điểm trên của các generalized class( nằm trong System.Collection namespace). Các lớp generic, các phương thức generic sử dụng tham số kiểu(type parameter), tham số kiểu sẽ chỉ ra kiểu đối tượng mà lớp, phương thức sẽ thao tác. Generic and Iterator System.Collection.Generic namespace Generic and Iterator System.Collections.Generic Cú pháp khai báo đối tượng lớp generic ClassName objName = new ClassName(); Ví dụ: //ArrayList a = new ArrayList(); List a = new List(); List empList = new List(); Stack st = new Stack(); Ví dụ DEMO Generic and Iterator Icomparable và Icomparer Interface Nếu tập hợp là số nguyên hay chuỗi khi đó chúng ta chỉ việc đơn giản gọi phương thức sort ra để sắp xếp(mặc định sắp theo thứ tự tăng dần, muôn sắp xêp giản dần chúng ta có thể dùng . | Bài 12 Generic và Iterator Ôn tập lại bài cũ Khái niệm Collection System.Collection namespace ArrayList Hashtable SortedList Dictionary Stack Queue LinkedList Subject name / Session# / of Totalpage Nội dung trình bày Generic là gì? System.Collections.Generic namespace Icomparable và Icomparer Interface Generic class Generic method Generic interface Iterator là gì? Tạo iterator Generic and Iterator Vấn đề của generalized class và sự ra đời của kỹ thuật Generic? using System.Collections; ArrayList myList = new ArrayList(); Employee myEmp = new Employee(); myList.Add(myEmp); myEmp = (Employee)myList[0]; ArrayList myList = new ArrayList(); int myInt = 99; myList.Add(myInt); // box the int to an object myInt = (int)myList.[0]; // unbox the object to an int Generic and Iterator Vấn đề của generalized class và sự ra đời của kỹ thuật Generic? Các lớp trong System.Collection namespace là các generalized classes Khi sử dụng, chúng ta luôn phải ép kiểu(cast), chương trình luôn phải thực hiện