A. 哈希集 是一个无序的 独特元素 .在 系统收藏。通用的 名称空间。它用于我们希望防止在集合中插入重复项的情况。就性能而言,它比列表要好。 哈希集
null
语法:
mySet.Contains(T item);
在这里 迈塞特 是哈希集的名称,并且 项目 是要在哈希集中定位的必需元素
返回类型: 此方法返回 符合事实的 如果 哈希集
下面给出了一些例子,以更好地理解实施:
例1:
// C# code to check if a HashSet // contains the specified element using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a HashSet of strings HashSet< string > mySet = new HashSet< string >(); // Inserting elements in HashSet mySet.Add( "DS" ); mySet.Add( "C++" ); mySet.Add( "Java" ); mySet.Add( "JavaScript" ); // Check if a HashSet contains // the specified element if (mySet.Contains( "Java" )) Console.WriteLine( "Required Element is present" ); else Console.WriteLine( "Required Element is not present" ); } } |
输出:
Required Element is present
例2:
// C# code to check if a HashSet // contains the specified element 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); } // Check if a HashSet contains // the specified element if (mySet.Contains(5)) Console.WriteLine( "Required Element is present" ); else Console.WriteLine( "Required Element is not present" ); } } |
输出:
Required Element is not present
参考:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END