Dictionary.System.Collections.IDictionary.Contains メソッド
アセンブリ: 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)
private: virtual bool System.Collections.IDictionary.Contains ( Object^ key ) sealed = IDictionary::Contains
戻り値
指定したキーを持つ要素が IDictionary に格納されている場合は true。それ以外の場合は false。



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 /> } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDictionary.System.Collections.IDictionary.Contains メソッドを検索する場合は、下記のリンクをクリックしてください。

- Dictionary.System.Collections.IDictionary.Contains メソッドのページへのリンク