
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Check if the SortedSet contains a specific element in C#
To check if the SortedSet contains a specific element, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ SortedSet<string> set1 = new SortedSet<string>(); set1.Add("CD"); set1.Add("CD"); set1.Add("CD"); set1.Add("CD"); Console.WriteLine("Elements in SortedSet1..."); foreach (string res in set1){ Console.WriteLine(res); } Console.WriteLine("Does the SortedSet1 contains the element DE? = "+set1.Contains("DE")); SortedSet<string> set2 = new SortedSet<string>(); set2.Add("BC"); set2.Add("CD"); set2.Add("DE"); set2.Add("EF"); set2.Add("AB"); set2.Add("HI"); set2.Add("JK"); Console.WriteLine("Elements in SortedSet2..."); foreach (string res in set2){ Console.WriteLine(res); } Console.WriteLine("SortedSet2 is a superset of SortedSet1? = "+set2.IsSupersetOf(set1)); } }
Output
This will produce the following output −
Elements in SortedSet1... CD Does the SortedSet1 contains the element DE? = False Elements in SortedSet2... AB BC CD DE EF HI JK SortedSet2 is a superset of SortedSet1? = True
Example
Let us see another example -
Let us see another example: using System; using System.Collections.Generic; public class Demo { public static void Main(){ SortedSet<int> mySet = new SortedSet<int>(); mySet.Add(100); mySet.Add(200); mySet.Add(300); mySet.Add(400); Console.WriteLine("Elements in SortedSet..."); foreach (int res in mySet){ Console.WriteLine(res); } Console.WriteLine("Does the SortedSet contains the element 400? = "+mySet.Contains(400)); } }
Output
This will produce the following output −
Elements in SortedSet... 100 200 300 400 Does the SortedSet contains the element 400? = True
- Related Articles
- Check if the Hashtable contains a specific value in C#
- Check if the Hashtable contains a specific Key in C#
- Check if the StringDictionary contains a specific key in C#
- Check if the StringDictionary contains a specific value in C#
- Check if ListDictionary contains a specific key in C#
- How to use selenium to check if element contains specific class attribute?
- Check if a HashSet contains the specified element in C#
- Check if OrderedDictionary collection contains a specific key in C#
- Check if a SortedList object contains a specific value in C#
- Check if a Stack contains an element in C#
- How to check if the string contains the specific word?
- How to check if a string contains a specific sub string?
- How to check if a slice contains an element in Golang?
- Method to check if array element contains a false value in JavaScript?
- Check if a SortedSet is a subset of the specified collection in C#

Advertisements