Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

C#에서 ListDictionary의 값을 포함하는 ICollection 가져오기


ListDictionary의 값을 포함하는 ICollection을 가져오려면 코드는 다음과 같습니다. -

예시

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      ListDictionary listDict = new ListDictionary();
      listDict.Add("1", "Laptop");
      listDict.Add("2", "Tablet");
      listDict.Add("3", "Desktop");
      listDict.Add("4", "Speaker");
      listDict.Add("5", "Earphone");
      listDict.Add("6", "Headphone");
      ICollection col = listDict.Values;
      foreach(String s in col){
         Console.WriteLine(s);
      }
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Laptop
Tablet
Desktop
Speaker
Earphone
Headphone

예시

다른 예를 살펴보겠습니다 -

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      ListDictionary listDict = new ListDictionary();
      listDict.Add("A", "Tom");
      listDict.Add("B", "John");
      listDict.Add("C", "Kevin");
      listDict.Add("D", "Tim");
      ICollection col = listDict.Values;
      foreach(String s in col){
         Console.WriteLine(s);
      }
   }
}

출력

이것은 다음과 같은 출력을 생성합니다 -

Tom
John
Kevin
Tim