A. 哈希集 是独特元素的无序集合。它属于 系统收藏。通用的 名称空间。它用于我们希望防止在集合中插入重复项的情况。就性能而言,它比列表要好。 哈希集
null
语法:
mySet1.IsProperSupersetOf(mySet2);
在这里 mySet1 和 mySet2 有两个哈希集。
返回值: 函数返回 符合事实的 如果 mySet1 是的适当超集 mySet2 ,否则返回 错误的 .
例外情况: 这种方法会给你 无理例外 如果哈希集为空。
下面给出了一些例子,以更好地理解实施:
例1:
// C# code to Check if a HashSet is a proper // superset of the specified collection using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a HashSet of integers HashSet< int > mySet1 = new HashSet< int >(); // Inserting elements into HashSet mySet1 for ( int i = 10; i < 20; i++) { mySet1.Add(i); } // Creating a HashSet of integers HashSet< int > mySet2 = new HashSet< int >(); // Inserting elements into HashSet mySet2 for ( int i = 0; i < 25; i++) { mySet2.Add(i); } // Checking if mySet1 is Proper Superset Of mySet2 // The function returns true if the condition // satisfies, else returns false Console.WriteLine(mySet1.IsProperSupersetOf(mySet2)); } } |
输出:
False
例2:
// C# code to Check if a HashSet is a proper // superset of the specified collection using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a HashSet of strings HashSet< string > mySet1 = new HashSet< string >(); // Inserting elements into HashSet mySet1 mySet1.Add( "India" ); mySet1.Add( "Japan" ); mySet1.Add( "USA" ); mySet1.Add( "Spain" ); mySet1.Add( "Italy" ); // Creating a HashSet of strings HashSet< string > mySet2 = new HashSet< string >(); // Inserting elements into HashSet mySet2 mySet2.Add( "USA" ); mySet2.Add( "Spain" ); mySet2.Add( "Italy" ); // Checking if mySet1 is Proper Superset Of mySet2 // The function returns true if the condition // satisfies, else returns false Console.WriteLine(mySet1.IsProperSupersetOf(mySet2)); } } |
输出:
True
参考:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END