A. 哈希集 是一个无序的 独特元素 .在 系统收藏。通用的 名称空间。它用于我们希望防止在集合中插入重复项的情况。就性能而言,它比列表要好。你可以用 哈希集
null
语法:
mySet.Count;
在这里 迈塞特 散列集是什么
下面给出了一些例子,以更好地理解实施:
例1:
// C# code to get the number of // elements that are contained in HashSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a HashSet of integers HashSet< int > mySet = new HashSet< int >(); // Inserting elements in HashSet for ( int i = 0; i < 5; i++) { mySet.Add(i * 2); } // To get the number of // elements that are contained in HashSet Console.WriteLine(mySet.Count); } } |
输出:
5
例2:
// C# code to get the number of // elements that are contained in HashSet using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a HashSet of integers HashSet< int > mySet = new HashSet< int >(); // To get the number of // elements that are contained in HashSet. // Note that, here the HashSet is empty Console.WriteLine(mySet.Count); } } |
输出:
0
参考:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END