SortedList 개체의 지정된 인덱스에서 값을 가져오려면 코드는 다음과 같습니다. -
예
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add("A", "Jacob");
list.Add("B", "Sam");
list.Add("C", "Tom");
list.Add("D", "John");
list.Add("E", "Tim");
list.Add("F", "Mark");
list.Add("G", "Gary");
Console.WriteLine("Value at index 2 = "+list.GetByIndex(2));
Console.WriteLine("Value at index 5 = "+list.GetByIndex(5));
Console.WriteLine("Value at index 6 = "+list.GetByIndex(6));
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Value at index 2 = Tom Value at index 5 = Mark Value at index 6 = Gary
예
다른 예를 살펴보겠습니다 -
using System;
using System.Collections;
public class Demo {
public static void Main(String[] args) {
SortedList list = new SortedList();
list.Add(1, "One");
list.Add(2, "Two");
list.Add(3, "Three");
list.Add(4, "Four");
list.Add(5, "Five");
Console.WriteLine("Value at index 0 = "+list.GetByIndex(0));
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
Value at index 0 = One