所以,我有这个从 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");
}
现在,当我单步执行并到达Log()
函数的最后一个,并将鼠标悬停在 上时RigInfo
,Visual Studio 智能感知显示给我RigInfo{string[30]}
。现在,我一直明白这= new string[9]
将创建一个 9 元素数组。那么为什么允许有 30 个元素呢?当我运行程序时,这个数组没有任何错误或任何东西。事实上,它的工作方式正是我在整体方案中所需要的方式。感谢您在理解它的方式和原因方面提供的任何和所有帮助。还附上截图以获得更好的视觉帮助。