1. 概要
SortedList<int, int> keyValuePairs = new SortedList<int, int>();
keyValuePairs.Add(arrayInt[i], arrayInt[i]);
2 代码
using System;
using System.Collections.Generic;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
int[] arrayInt = { 5, 2, 3, 1, 4 };
Console.WriteLine("插入前的顺序");
for (int i = 0; i < arrayInt.Length; i++)
{
Console.WriteLine(arrayInt[i]);
}
SortedList<int, int> keyValuePairs = new SortedList<int, int>();
for (int i = 0; i < arrayInt.Length; i++) {
keyValuePairs.Add(arrayInt[i], arrayInt[i]);
}
Console.WriteLine("插入后的顺序");
foreach (int key in keyValuePairs.Keys) {
Console.WriteLine(key);
}
Console.ReadKey();
}
}
}
3.运行结果