StringCollection.Contains メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StringCollection.Contains メソッドの意味・解説 

StringCollection.Contains メソッド

指定した文字列StringCollection 内にあるかどうか確認します

名前空間: System.Collections.Specialized
アセンブリ: System (system.dll 内)
構文構文

Dim instance As StringCollection
Dim value As String
Dim returnValue As Boolean

returnValue = instance.Contains(value)
public bool Contains (
    string value
)
public:
bool Contains (
    String^ value
)

パラメータ

value

StringCollection 内で検索する文字列。値は null 参照 (Visual Basic では Nothing) に設定できます

戻り値
valueStringCollection存在する場合trueそれ以外場合false

解説解説
使用例使用例

StringCollection要素検索する例を次に示します

Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesStringCollection   

   Public Shared Sub Main()

      ' Creates and initializes a new StringCollection.
      Dim myCol As New StringCollection()
      Dim myArr() As [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")
 Then
         Console.WriteLine("The collection contains ""orange""
 at index {0}.", myCol.IndexOf("orange"))
      Else
         Console.WriteLine("The collection does not contain ""orange"".")
      End If 

   End Sub 'Main

   Public Shared Sub PrintValues(myCol
 As IEnumerable)
      Dim obj As [Object]
      For Each obj In  myCol
         Console.WriteLine("   {0}", obj)
      Next obj
      Console.WriteLine()
   End Sub 'PrintValues

End Class 'SamplesStringCollection
 


'This code produces the following output.
'
'Initial contents of the StringCollection:
'   RED
'   orange
'   yellow
'   RED
'   green
'   blue
'   RED
'   indigo
'   violet
'   RED
'
'The collection contains "orange" at index 1.
'

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();
   }

}

/*
This code produces the following output.

Initial contents of the StringCollection:
   RED
   orange
   yellow
   RED
   green
   blue
   RED
   indigo
   violet
   RED

The collection contains "orange" at index 1.

*/
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void PrintValues( IEnumerable^ myCol );
int main()
{
   
   // Creates and initializes a new StringCollection.
   StringCollection^ myCol = gcnew StringCollection;
   array<String^>^myArr = {"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\"."
 );
}

void PrintValues( IEnumerable^ myCol )
{
   IEnumerator^ myEnum = myCol->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ obj = safe_cast<Object^>(myEnum->Current);
      Console::WriteLine( "   {0}", obj );
   }

   Console::WriteLine();
}

/*
This code produces the following output.

Initial contents of the StringCollection:
   RED
   orange
   yellow
   RED
   green
   blue
   RED
   indigo
   violet
   RED

The collection contains "orange" at index 1.

*/
import System.* ;
import System.Collections.* ;
import System.Collections.Specialized.* ;

public class SamplesStringCollection
{
    public static void main(String[]
 args)
    {
        // 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}.",System.Convert.ToString(myCol.IndexOf("orange")));
        }
        else {        
            Console.WriteLine("The collection does not contain \"orange\".");
        } 
    } //main        
        
    public static void PrintValues(IEnumerable
 myCol)
    {
        Object obj = null;
        IEnumerator objEnum = myCol.GetEnumerator();

        while (objEnum.MoveNext()) {        
            obj = objEnum.get_Current();
            Console.WriteLine("   {0}", obj);
        }

        Console.WriteLine();
    } //PrintValues
} //SamplesStringCollection 

/*
This code produces the following output.

Initial contents of the StringCollection:
   RED
   orange
   yellow
   RED
   green
   blue
   RED
   indigo
   violet
   RED

The collection contains "orange" at index 1.

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StringCollection クラス
StringCollection メンバ
System.Collections.Specialized 名前空間
IndexOf
その他の技術情報
カルチャを認識しい文字操作実行


このページでは「.NET Framework クラス ライブラリ リファレンス」からStringCollection.Contains メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からStringCollection.Contains メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からStringCollection.Contains メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

StringCollection.Contains メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StringCollection.Contains メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS