微軟在 .NET 3.5 新增了一個 HashSet 類,在 .NET 4 新增了一個 SortedSet 類. .NET Collection 函數庫的 HashSet、SortedSet 這兩個泛型的類,都實現了 System.Collections.Generic.ISet 接口.
參見如下示例:
varset=newHashSet<int>(){5,9,2,1,2,2,3,7,4,9,9};foreach(intelementinset)Response.Write(string.Format("{0}",element)); 執行結果:
同樣的代碼,把 HashSet 改成 SortedSet,如下: varset=newSortedSet<int>(){5,9,2,1,2,2,3,7,4,9,9};foreach(intelementinset)Response.Write(string.Format("{0}",element)); 執行結果:
|
說明:
Set.Contains("value"); 返回true或false。
5.SortedSet對象,可以調用GetViewBetween、Max、Min 方法。
6.除了SortedSet外,System.Collections.Generic命名空間下,還提供了SortedDictionary和SortedList兩個類。
新聞熱點
疑難解答