Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Generics vs Non-Generics trong C#


Hai loại collection: non-generic và generic.

Generics

Chứa phần tử cùng kiểu dữ liệu. Ví dụ: List, Dictionary, HashSet.

Dictionary: Dictionary<TKey, TValue> trong System.Collections.Generic.

HashSet: Loại bỏ duplicate, optimized set collection.

Non-Generics

Chứa phần tử khác kiểu. Ví dụ: ArrayList, BitArray.

ArrayList: Collection ordered, index individually, tự resize.

BitArray: Mảng biểu diễn nhị phân 1/0, dùng khi không biết trước số bit.