class Program
{
static int[] x = {1, 2, 3, 4};
static int z = 10;
static int c = 20;
static int v = 30;
static int b = 40;
static void Main(string[] args)
{
Console.WriteLine(x[0]);
Console.ReadLine();
}
public Program()
{
x = new int[4]{z, c, v, b};
}
在此代码片段中,我尝试通过构造函数更新具有不同变量的数组。但是,当我调试时,它只打印原始的 [0] 索引。
我觉得我在做一些非常愚蠢的事情而且我只是累了,但谁能告诉我为什么数组没有更新?
最佳答案
您不是在创建 Program
类型的对象,因此构造函数永远不会运行。
关于c# - 通过构造函数更新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17392168/