gpt4 book ai didi

c# - 为什么数组的元素比我定义的多?

转载 作者:太空狗 更新时间:2023-10-29 22:10:57 24 4
gpt4 key购买 nike

所以,我得到了这个从 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 intellisense 会显示 RigInfo{string[30]}.现在,我一直明白 = new string[9] 会创建一个 9 元素数组。那么为什么允许有 30 个元素呢?当我运行该程序时,我没有收到任何关于此数组的错误或任何信息。事实上,它的工作方式正是我在整体方案中需要的方式。感谢您提供的所有帮助,帮助您理解这是如何以及为什么会这样。还附上屏幕截图以获得更好的视觉帮助。

Confusing intellisense

最佳答案

这里:

RigInfo = File.ReadAllLines(fileLocation[1] + "\\hddrigsite.ini");

您正在为变量分配新值。在本例中为新字符串[]。

关于c# - 为什么数组的元素比我定义的多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13277737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com