c#中如何将一个变量的值赋给数组的某一特定位置c#中如何将一个变量的值赋给数组的某一特定位置

c#中如何将一个变量的值赋给数组的某一特定位置,是不是可以用SetValue

List对象可以用Insert方法,数组直接用下标赋值

img

using System;
using System.Collections.Generic;
namespace ConsoleApp1
{ 
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<string>() { "11", "22", "33" };
            list.Insert(1, "44");
            Console.WriteLine(String.Join(",", list));//11,44,22,33
            var arr = new string[4];
            arr[1] = "44";
            Console.WriteLine(String.Join(",", arr));//,44,,
            Console.ReadKey();
        }
    }
}