本文整理匯總了C#中System.Collections.Specialized.StringCollection.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# StringCollection.Contains方法的具體用法?C# StringCollection.Contains怎麽用?C# StringCollection.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Specialized.StringCollection
的用法示例。
在下文中一共展示了StringCollection.Contains方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Collections;
using System.Collections.Specialized;
public class SamplesStringCollection {
public static void Main() {
// Creates and initializes a new StringCollection.
StringCollection myCol = new StringCollection();
String[] myArr = new String[] { "RED", "orange", "yellow", "RED", "green", "blue", "RED", "indigo", "violet", "RED" };
myCol.AddRange( myArr );
Console.WriteLine( "Initial contents of the StringCollection:" );
PrintValues( myCol );
// Checks whether the collection contains "orange" and, if so, displays its index.
if ( myCol.Contains( "orange" ) )
Console.WriteLine( "The collection contains \"orange\" at index {0}.", myCol.IndexOf( "orange" ) );
else
Console.WriteLine( "The collection does not contain \"orange\"." );
}
public static void PrintValues( IEnumerable myCol ) {
foreach ( Object obj in myCol )
Console.WriteLine( " {0}", obj );
Console.WriteLine();
}
}
輸出:
Initial contents of the StringCollection: RED orange yellow RED green blue RED indigo violet RED The collection contains "orange" at index 1.