Determines whether the specified string is in the StringCollection. : StringCollection « Collections Data Structure « C# / C Sharp






Determines whether the specified string is in the StringCollection.

 

using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringCollection  {

   public static void Main()  {
      StringCollection myCol = new StringCollection();
      String[] myArr = new String[] { "a", "o" };
      
      myCol.AddRange( myArr );
      PrintValues( myCol );
      
      if ( myCol.Contains( "a" ) )
         Console.WriteLine( myCol.IndexOf( "orange" ) );
      else
         Console.WriteLine( "does not contain " );
   }
   public static void PrintValues( IEnumerable myCol )  {
      foreach ( Object obj in myCol )
         Console.WriteLine( "   {0}", obj );
      Console.WriteLine();
   }
}

   
  








Related examples in the same category

1.StringCollection represents a collection of strings.
2.Adds a string to the end of the StringCollection.
3.Removes all the strings from the StringCollection.
4.Copies the entire StringCollection values to a one-dimensional array of strings
5.StringEnumerator supports a simple iteration over a StringCollection.