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