所以,我有这个从INI文件中读取的函数:
private void GetRigInfo()
{
RigInfo = new string[9];
var fileLocation = new string[2];
// The problem is that there's no telling where the hddrigsite.ini will be
stored. So, we have to find out where it is from the hddconfig.ini.
Log("Locating rig info");
// There's no telling if this will be on a 32 or 64 bit OS. Check for both
var rigInfoLocation = File.ReadAllLines(Environment.Is64BitOperatingSystem ?
@"C:\Program Files (x86)\HDD DrillView\hddconfig.ini" :
@"C:\Program Files\HDD DrillView\hddconfig.ini");
// This should get us the location of the rigsite info we need.
foreach (var s in rigInfoLocation.Where(s => s.Contains("data_dir")))
{
fileLocation = s.Split('=');
}
RigInfo = File.ReadAllLines(fileLocation[1] + "\\hddrigsite.ini");
Log("Rig info found");
}
Run Code Online (Sandbox Code Playgroud)
现在,当我单步执行并到达Log()函数中的最后一个,并且我将鼠标悬停在上面时RigInfo,Visual Studio intellisense会向我显示RigInfo{string[30]}.现在,我一直都明白= new string[9]会创建一个9元素数组.那为什么它允许有30个元素呢?当我运行程序时,在这个数组中我没有任何错误或任何错误.事实上,它只是在整体方案中我需要它的方式.感谢任何和所有帮助,了解它是如何以及为什么这样.还附有截图,以获得更好的视觉辅助

这里 :
RigInfo = File.ReadAllLines(fileLocation[1] + "\\hddrigsite.ini");
Run Code Online (Sandbox Code Playgroud)
您正在为变量分配一个新值.在这种情况下,新的字符串[].