選取集合類別Selecting a Collection Class

請務必謹慎選擇您的集合類別。Be sure to choose your collection class carefully. 使用錯誤的類型可能會限制您使用集合。Using the wrong type can restrict your use of the collection.

重要

避免在 System.Collections 命名空間中使用那些型別。Avoid using the types in the System.Collections namespace. 由於泛型和並行版本的集合類型較安全,而且提供其他增強功能,因此建議使用這些版本。The generic and concurrent versions of the collections are recommended because of their greater type safety and other improvements.

請考慮下列問題:Consider the following questions:

LINQ to Objects 和 PLINQLINQ to Objects and PLINQ

只要物件類型實作 IEnumerableIEnumerable<T>,LINQ to Objects 就可讓開發人員使用 LINQ 查詢以存取記憶體內的物件。LINQ to Objects enables developers to use LINQ queries to access in-memory objects as long as the object type implements IEnumerable or IEnumerable<T>. LINQ 查詢提供一般模式以存取資料,比標準的 foreach 迴圈更精簡、可讀性更高,並提供篩選、排序和群組功能。LINQ queries provide a common pattern for accessing data, are typically more concise and readable than standard foreach loops, and provide filtering, ordering, and grouping capabilities. 如需詳細資訊,請參閱 LINQ to Objects (C#)LINQ to Objects (Visual Basic)For more information, see LINQ to Objects (C#) and LINQ to Objects (Visual Basic).

PLINQ 提供 LINQ to Objects 的平行實作,這項實作透過更有效率地使用多核心電腦,在許多情況下會提供更快的查詢執行速度。PLINQ provides a parallel implementation of LINQ to Objects that can offer faster query execution in many scenarios, through more efficient use of multi-core computers. 如需詳細資訊,請參閱 Parallel LINQ (PLINQ)For more information, see Parallel LINQ (PLINQ).

另請參閱See also