Dictionary.System.Collections.IDictionary.Contains メソッドとは? わかりやすく解説

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

Dictionary.System.Collections.IDictionary.Contains メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定したキー要素IDictionary格納されているかどうか確認します

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

Private Function System.Collections.IDictionary.Contains
 ( _
    key As Object _
) As Boolean Implements
 IDictionary.Contains
Dim instance As Dictionary(Of
 TKey, TValue)
Dim key As Object
Dim returnValue As Boolean

returnValue = CType(instance, IDictionary).Contains(key)
bool IDictionary.Contains (
    Object key
)
private:
virtual bool System.Collections.IDictionary.Contains (
    Object^ key
) sealed = IDictionary::Contains

パラメータ

key

IDictionary 内で検索されるキー

戻り値
指定したキー持つ要素IDictionary格納されている場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentNullException

keynull 参照 (Visual Basic では Nothing) です。

解説解説

このメソッドは、key が、Dictionaryキーの型 TKey代入できない型である場合に、false返します

このメソッドは O(1) 操作近くなります

使用例使用例

Dictionary で、System.Collections.IDictionary インターフェイスSystem.Collections.IDictionary.Contains メソッド使用する方法次のコード例示します。この例では、データ型適切でないキー指定した場合に、メソッドによって false返されることを示してます。

次のコード例は、System.Collections.IDictionary.Add メソッドトピック取り上げている例および出力一部分です。

Imports System
Imports System.Collections
Imports System.Collections.Generic

Public Class Example
    
    Public Shared Sub Main()
 

        ' Create a new dictionary of strings, with string keys,
        ' and access it using the IDictionary interface.
        '
        Dim openWith As IDictionary = _
            New Dictionary(Of String,
 String)
        
        ' Add some elements to the dictionary. There are no 
        ' duplicate keys, but some of the values are duplicates.
        ' IDictionary.Add throws an exception if incorrect types
        ' are supplied for key or value.
        openWith.Add("txt", "notepad.exe")
        openWith.Add("bmp", "paint.exe")
        openWith.Add("dib", "paint.exe")
        openWith.Add("rtf", "wordpad.exe")
<br /><span space="preserve">...</span><br
 />        ' Contains can be used to test keys before inserting
 
        ' them.
        If Not openWith.Contains("ht")
 Then
            openWith.Add("ht", "hypertrm.exe")
            Console.WriteLine("Value added for key = ""ht"":
 {0}", _
                openWith("ht"))
        End If

        ' IDictionary.Contains returns False if the wrong data 
        ' type is supplied.
        Console.WriteLine("openWith.Contains(29.7) returns {0}",
 _
            openWith.Contains(29.7))
<br /><span space="preserve">...</span><br
 />
    End Sub

End Class
using System;
using System.Collections;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        // Create a new dictionary of strings, with string keys,
        // and access it using the IDictionary interface.
        //
        IDictionary openWith = new Dictionary<string,
 string>();

        // Add some elements to the dictionary. There are no 
        // duplicate keys, but some of the values are duplicates.
        // IDictionary.Add throws an exception if incorrect types
        // are supplied for key or value.
        openWith.Add("txt", "notepad.exe");
        openWith.Add("bmp", "paint.exe");
        openWith.Add("dib", "paint.exe");
        openWith.Add("rtf", "wordpad.exe");
<br /><span space="preserve">...</span><br /> 
       // Contains can be used to test keys before inserting 
        // them.
        if (!openWith.Contains("ht"))
        {
            openWith.Add("ht", "hypertrm.exe");
            Console.WriteLine("Value added for key = \"ht\":
 {0}", 
                openWith["ht"]);
        }

        // IDictionary.Contains returns false if the wrong data
        // type is supplied.
        Console.WriteLine("openWith.Contains(29.7) returns {0}",
            openWith.Contains(29.7));
<br /><span space="preserve">...</span><br /> 
   }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

Dictionary.System.Collections.IDictionary.Contains メソッドのお隣キーワード
検索ランキング

   

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



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

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

©2024 GRAS Group, Inc.RSS