C# 从非常大的整数数组c初始化特定索引#

C# 从非常大的整数数组c初始化特定索引#,c#,arrays,initialization,C#,Arrays,Initialization,我想创建一个非常大的数组,并在创建它们时用0以外的其他标准值填充其中的一些数组。 我如何从一开始就做到这一点 我知道它是如何处理int-MyInt=12的原语的 但是现在我想更改索引中数组的值:123, 其他每个值都应以0开头 public static class Arrays { public static bool[] Bools = new bool[20000]; public static int[] Integers = new int[20000]; pu

我想创建一个非常大的数组,并在创建它们时用0以外的其他标准值填充其中的一些数组。 我如何从一开始就做到这一点

我知道它是如何处理int-MyInt=12的原语的

但是现在我想更改索引中数组的值:123, 其他每个值都应以0开头

public static class Arrays
{
    public static bool[] Bools = new bool[20000];
    public static int[] Integers = new int[20000];
    public static float[] Floats = new float[20000];

    //Integers[123] = 100; This obviously doesnt work.
}
使用类的名称初始化静态成员:

public static class Arrays
{
    static Arrays()
    {
        Bools =  new bool[20000];
        Floats = new float[20000];
        Integers = new int[20000];
        Integers[123] = 100;
    }

    public static bool[] Bools;
    public static int[] Integers;
    public static float[] Floats;
}

将您的代码放入静态构造函数中…索引器集合初始值设定项语法在这里不起作用似乎很遗憾。。。想象一下
=newint[20000]{[123]=100}@MarcGravel:那很好,但我从来没有真正错过过。可能会让人困惑