C#
 Computer >> コンピューター >  >> プログラミング >> C#

SortedListオブジェクトにC#の特定の値が含まれているかどうかを確認します


SortedListオブジェクトに特定の値が含まれているかどうかを確認するには、コードは次のとおりです-

using System;
using System.Collections;
public class Demo {
   public static void Main(){
      SortedList list = new SortedList();
      list.Add("1", "One");
      list.Add("2", "Two");
      list.Add("3", "Three");
      list.Add("4", "Four");
      list.Add("5", "Five");
      list.Add("6", "Six");
      list.Add("7", "Seven");
      list.Add("8", "Eight");
      Console.WriteLine("Key and Value of SortedList....");
      foreach(DictionaryEntry k in list )
      Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
      Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Five"));
   }
}

出力

これにより、次の出力が生成されます-

Key and Value of SortedList....
Key: 1, Value: One
Key: 2, Value: Two
Key: 3, Value: Three
Key: 4, Value: Four
Key: 5, Value: Five
Key: 6, Value: Six
Key: 7, Value: Seven
Key: 8, Value: Eight
Is the SortedList having the value? True

別の例を見てみましょう-

using System;
using System.Collections;
public class Demo {
   public static void Main(){
      SortedList list = new SortedList();
      list.Add("1", "One");
      list.Add("2", "Two");
      list.Add("3", "Three");
      list.Add("4", "Four");
      list.Add("5", "Five");
      list.Add("6", "Six");
      list.Add("7", "Seven");
      list.Add("8", "Eight");
      Console.WriteLine("Key and Value of SortedList....");
      foreach(DictionaryEntry k in list )
      Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value );
      Console.WriteLine("Is the SortedList having the value? "+list.ContainsValue("Tenth"));
   }
}

出力

これにより、次の出力が生成されます-

Key and Value of SortedList....
Key: 1, Value: One
Key: 2, Value: Two
Key: 3, Value: Three
Key: 4, Value: Four
Key: 5, Value: Five
Key: 6, Value: Six
Key: 7, Value: Seven
Key: 8, Value: Eight
Is the SortedList having the value? False

  1. SortedSetにC#の特定の要素が含まれているかどうかを確認します

    SortedSetに特定の要素が含まれているかどうかを確認するには、コードは次のとおりです- 例 using System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet<string> set1 = new SortedSet<string>();       set1.Add("CD");    

  2. ハッシュテーブルにC#の特定の値が含まれているかどうかを確認します

    ハッシュテーブルに特定の値が含まれているかどうかを確認するためのコードは、次のとおりです- 例 using System; using System.Collections; public class Demo {    public static void Main(){       Hashtable hash = new Hashtable();       hash.Add("1", "A");       hash.Add("