목록과 같은 동적 데이터 구조가 필요합니다.
일반 (즉, 목록) 또는 비 일반 (목록) 버전 중 하나를 사용할 수 있습니다. 목록을 사용하면 항목을 동적으로 추가 또는 삽입하고 색인을 결정하며 원하는대로 항목을 제거 할 수 있습니다.
목록 작업을 사용함에 따라 목록 크기가 동적으로 커지고 축소됩니다. 사용하여 사전에 의해
// instantiation of an empty list
List<Image> list = new List<Image>();
// create ten images and add them to the list (append at the end of the list at each iteration)
for (int i = 0; i <= 9; i++) {
Image img = new Image();
list.Add(img);
}
// remove every second image from the list starting at the beginning
for (int i = 0; i <= 9; i += 2) {
list.RemoveAt(i);
}
// insert a new image at the first position in the list
Image img1 = new Image();
list.Insert(0, img1);
// insert a new image at the first position in the list
IMage img2 = new Image();
list.Insert(0, img2);
대체 방법 :
Dictionary<string, Image> dict = new Dictionary<string, Image>();
for (int i = 0; i <= 9; i++) {
Image img = new Image();
// suppose img.Name is an unique identifier then it is used as the images keys
// in this dictionary. You create a direct unique mapping between the images name
// and the image itself.
dict.Add(img.Name, img);
}
// that's how you would use the unique image identifier to refer to an image
Image img1 = dict["Image1"];
Image img2 = dict["Image2"];
Image img3 = dict["Image3"];
이게 좋겠지 만, 파일 이름과 같은 일부 키워드로 개체를 현지화 할 수 있습니까? – phil13131
번호 인덱스로 색인화 된 목록으로, 정수 여야합니다. 숫자 인덱스가 아닌 다른 값으로 이미지의 주소를 지정하려면 사전을 사용해야합니다. 나는 내 대답을 연장 할 것이다. –
고마워, 리드 코세 이는 또한 사전을 제안했다. – phil13131