Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the array have more elements than I've defined?

Tags:

arrays

c#

So, I've got this function which reads from an INI file:

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");
}

Now, when I step through, and get to the last Log() in the function, and I hover over RigInfo, Visual Studio intellisense shows me RigInfo{string[30]}. Now, I've always understood that = new string[9] would create a 9 element array. So why is it allowed to have 30 elements? When I run the program, I get no errors or anything when it comes to this array. Matter of fact, it works just the way that I need it to in the overall scheme of things. Thanks for any and all help in understanding how and why this is the way it is. Also attached screenshot for better visual aid.

Confusing intellisense

like image 435
PiousVenom Avatar asked Nov 07 '12 20:11

PiousVenom


1 Answers

Here :

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

You are assigning the variable with a new value.. In this case a new string[].

like image 136
Jonas W Avatar answered Sep 27 '22 00:09

Jonas W