C#의 일반 컬렉션에는 ,
목록
List
예를 들어 보겠습니다. 여기 목록에 6개의 요소가 있습니다. -
예시
using System;
using System.Collections.Generic;
class Program {
static void Main() {
// Initializing collections
List myList = new List() {
"one",
"two",
"three",
"four",
"five",
"six"
};
Console.WriteLine(myList.Count);
}
} 출력
6
정렬 목록
정렬된 목록은 배열과 해시 테이블의 조합입니다. 여기에는 키 또는 색인을 사용하여 액세스할 수 있는 항목 목록이 포함되어 있습니다.
예를 들어 보겠습니다. 여기 SortedList에 4개의 요소가 있습니다 -
예시
using System;
using System.Collections;
namespace CollectionsApplication {
class Program {
static void Main(string[] args) {
SortedList sl = new SortedList();
sl.Add("001", "Tim");
sl.Add("002", "Steve");
sl.Add("003", "Bill");
sl.Add("004", "Tom");
if (sl.ContainsValue("Bill")) {
Console.WriteLine("This name is already in the list");
} else {
sl.Add("005", "James");
}
ICollection key = sl.Keys;
foreach (string k in key) {
Console.WriteLine(k + ": " + sl[k]);
}
}
}
} 출력
This name is already in the list 001: Tim 002: Steve 003: Bill 004: Tom