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.
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.
- 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 :