C#のDictionary.ContainsValue()メソッド
C#のDictionary.ContainsValue()メソッドは、Dictionary
構文
public bool ContainsValue (TValue val);
上記のValは検索する値です。
ここで、Dictionary.ContainsValue()メソッドを実装する例を見てみましょう-
例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
Dictionary<string, string> dict =
new Dictionary<string, string>();
dict.Add("One", "John");
dict.Add("Two", "Tom");
dict.Add("Three", "Jacob");
dict.Add("Four", "Kevin");
dict.Add("Five", "Nathan");
Console.WriteLine("Count of elements = "+dict.Count);
Console.WriteLine("\nKey/value pairs...");
foreach(KeyValuePair<string, string> res in dict){
Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);
}
if (dict.ContainsValue("Kevin"))
Console.WriteLine("Value found!");
else
Console.WriteLine("Value isn't in the dictionary!");
dict.Clear();
Console.WriteLine("Cleared Key/value pairs...");
foreach(KeyValuePair<string, string> res in dict){
Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);
}
Console.WriteLine("Count of elements now = "+dict.Count);
}
} 出力
これにより、次の出力が生成されます-
Count of elements = 5 Key/value pairs... Key = One, Value = John Key = Two, Value = Tom Key = Three, Value = Jacob Key = Four, Value = Kevin Key = Five, Value = Nathan Value found! Cleared Key/value pairs... Count of elements now = 0
ここで、Dictionary.ContainsValue()メソッドを実装する別の例を見てみましょう-
例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
Dictionary<string, string> dict =
new Dictionary<string, string>();
dict.Add("One", "Chris");
dict.Add("Two", "Steve");
dict.Add("Three", "Messi");
dict.Add("Four", "Ryan");
dict.Add("Five", "Nathan");
Console.WriteLine("Count of elements = "+dict.Count);
Console.WriteLine("\nKey/value pairs...");
foreach(KeyValuePair<string, string> res in dict){
Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);
}
if (dict.ContainsValue("Angelina"))
Console.WriteLine("Value found!");
else
Console.WriteLine("Value isn't in the dictionary!");
dict.Clear();
Console.WriteLine("Cleared Key/value pairs...");
foreach(KeyValuePair<string, string> res in dict){
Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);
}
Console.WriteLine("Count of elements now = "+dict.Count);
}
}
出力
これにより、次の出力が生成されます-
Count of elements = 5 Key/value pairs... Key = One, Value = Chris Key = Two, Value = Steve Key = Three, Value = Messi Key = Four, Value = Ryan Key = Five, Value = Nathan Value isn't in the dictionary! Cleared Key/value pairs... Count of elements now = 0
-
C#のChar.IsSymbol()メソッド
C#のChar.IsSymbol()メソッドは、指定された文字列の指定された位置にある文字が記号文字として分類されるかどうかを示します。 構文 public static bool IsSymbol (string str, int index); 上記では、strは文字列ですが、strで評価する文字の位置。 Char.IsSymbol()メソッドを実装する例を見てみましょう- 例 using System; public class Demo { public static void Main(){ bool res;
-
C#のDictionary.ContainsKey()メソッド
C#のDictionary.ContainsKey()メソッドは、Dictionary