

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a HashSet is a superset of the specified collection in C#
To check if a HashSet is a superset of the specified collection, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ HashSet<string> set1 = new HashSet<string>(); set1.Add("AB"); set1.Add("CD"); set1.Add("EF"); set1.Add("AB"); set1.Add("IJ"); set1.Add("KL"); set1.Add("EF"); set1.Add("OP"); Console.WriteLine("Elements in HashSet1"); foreach(string val in set1){ Console.WriteLine(val); } HashSet<string> set2 = new HashSet<string>(); set2.Add("EF"); set2.Add("KL"); Console.WriteLine("Elements in HashSet2"); foreach(string val in set2){ Console.WriteLine(val); } Console.WriteLine("Is set1 a superset of set2? "+set1.IsSupersetOf(set2)); } }
Output
This will produce the following output:
Elements in HashSet1 AB CD EF IJ KL OP Elements in HashSet2 EF KL Is set1 a superset of set2? True
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(){ HashSet<string> set1 = new HashSet<string>(); set1.Add("IJ"); set1.Add("KL"); set1.Add("EF"); set1.Add("OP"); Console.WriteLine("Elements in HashSet1"); foreach(string val in set1){ Console.WriteLine(val); } HashSet<string> set2 = new HashSet<string>(); set2.Add("KL"); set2.Add("MN"); set2.Add("OP"); set2.Add("QR"); Console.WriteLine("Elements in HashSet2"); foreach(string val in set2){ Console.WriteLine(val); } Console.WriteLine("Is set1 a superset of set2? "+set1.IsSupersetOf(set2)); } }
Output
This will produce the following output −
Elements in HashSet1 IJ KL EF OP Elements in HashSet2 KL MN OP QR Is set1 a superset of set2? False
- Related Questions & Answers
- Check if a HashSet is a proper superset of the specified collection in C#
- Check if a SortedSet is a superset of the specified collection in C#
- Check if a HashSet is a subset of the specified collection in C#
- Check if a SortedSet object is a proper superset of the specified collection in C#
- Check if a HashSet is a proper subset of the specified collection in C#
- Check if a HashSet and a specified collection share common element in C#
- Check if a Java HashSet Collection contains another Collection
- Check if a SortedSet is a subset of the specified collection in C#
- Check if HashSet and the specified collection contain the same elements in C#
- Check if a HashSet contains the specified element in C#
- Check if a SortedSet object is a proper subset of the specified collection in C#
- Check if SortedSet and a specified collection share common elements in C#
- Check if SortedSet and the specified collection contain the same elements in C#
- Remove the specified element from a HashSet in C#
- What is the HashSet, C# Set collection in C#?
Advertisements