C#のStringDictionaryで指定されたキーの値を取得または設定します
StringDictionaryで指定されたキーの値を取得または設定するには、コードは次のとおりです-
例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary myDict = new StringDictionary();
myDict.Add("1", "Tablet");
myDict.Add("2", "Desktop");
myDict.Add("3", "Speakers");
myDict.Add("4", "Laptop");
myDict.Add("5", "Notebook");
myDict.Add("6", "Ultrabook");
myDict.Add("7", "HDD");
myDict.Add("8", "SDD");
myDict.Add("9", "Headphone");
myDict.Add("10", "Earphone");
Console.WriteLine("Value for key 5 = "+myDict["5"]);
}
} 出力
これにより、次の出力が生成されます-
Value for key 5 = Notebook
例
別の例を見てみましょう-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary myDict = new StringDictionary();
myDict.Add("1", "Tablet");
myDict.Add("2", "Desktop");
myDict.Add("3", "Speakers");
myDict.Add("4", "Laptop");
myDict.Add("5", "Notebook");
myDict.Add("6", "Ultrabook");
myDict.Add("7", "HDD");
myDict.Add("8", "SDD");
myDict.Add("9", "Headphone");
myDict.Add("10", "Earphone");
Console.WriteLine("Value for key 5 = "+myDict["5"]);
myDict["5"] = "Flash Drive";
Console.WriteLine("Value for key 5 [Updated] = "+myDict["5"]);
}
} 出力
これにより、次の出力が生成されます-
Value for key 5 = Notebook Value for key 5 [Updated] = Flash Drive
-
StringDictionaryにC#の特定の値が含まれているかどうかを確認します
StringDictionaryに特定の値が含まれているかどうかを確認するためのコードは、次のとおりです- 例 using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ StringDictionary strDict1 = new StringDictionary(); strDict1.Add
-
StringDictionaryにC#の特定のキーが含まれているかどうかを確認します
StringDictionaryに特定のキーが含まれているかどうかを確認するためのコードは、次のとおりです- 例 using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ StringDictionary strDict1 = new StringDictionary(); strDict1.Ad