在 C# 中获取 SortedList 对象指定索引处的 value
要获取 SortedList 对象指定索引处的 value,代码如下 −
范例
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP