C# | Check if the specified string is in the StringCollection Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Contains(String) method is used to check whether the specified string is in the StringCollection or not. Syntax: public bool Contains (string value); Here, value is the string to locate in the StringCollection. The value can be null. Return Value: This method returns true if value is found in the StringCollection, otherwise it returns false. Note: The Contains method can confirm the existence of a string before performing further operations. This method performs a linear search, therefore, this method is an O(n) operation, where n is Count. Below programs illustrate the use of StringCollection.Contains(String) Method: Example 1 : CSHARP // C# code to check if the specified // string is in the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // creating a string array named myArr String[] myArr = new String[] { "A", "B", "C", "D", "E" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // checking if StringCollection // Contains "A" Console.WriteLine(myCol.Contains("A")); } } Output: True Example 2: CSHARP // C# code to check if the specified // string is in the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // creating a string array named myArr String[] myArr = new String[] { "2", "3", "4", "5", "6" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // checking if StringCollection // Contains "8" Console.WriteLine(myCol.Contains("8")); } } Output: False Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.contains?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Check if the specified string is in the StringCollection S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Specialized-Namespace CSharp-Specialized-StringCollection +1 More Similar Reads C# | Check if the StringCollection is read-only StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.IsReadOnly property is used to get a value indicating whether the StringCollection 1 min read C# | Check if StringCollection is synchronized (thread safe) StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.IsSynchronized property is used to get a value indicating whether access to the St 1 min read C# | Check if the StringDictionary contains a specific value StringDictionary.ContainsValue(String) method is used to check whether the StringDictionary contains a specific value or not. Syntax: public virtual bool ContainsValue (string value); Here, value is the value to locate in the StringDictionary. The value can be null. Return Value: The method returns 2 min read C# | Get or Set at specified index in StringCollection StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. Properties: StringCollection accepts null as a valid value and allows duplicate elements. String co 2 min read C# | Check if the StringDictionary contains a specific key StringDictionary.ContainsKey(String) method is used to check whether the StringDictionary contains a specific key or not. Syntax: public virtual bool ContainsKey (string key); Here, key is the key to locate in the StringDictionary. Return Value: This method returns true if the StringDictionary conta 2 min read Like