Xi Vix
Xi Vix

Reputation: 1361

unbounded array in visual c#?

By accident, it appears I am creating an unbounded array, which I didn't think was possible in c#. I am not getting any errors, and the code works, but I see no reference to the array declaration I used in online documentation. I tried using this method in other situations and I get an error every time. Why does this work?

Array arrLines;

arrLines = System.IO.File.ReadAllLines(strTargetFilePath2);
foreach (string strLine2 in arrLines)
{
eventLog1.WriteEntry(strLine2);
}

Upvotes: 0

Views: 158

Answers (1)

Array arrLines; does not actually create an array. It just sets up a variable that you can assign an array to.

You don't have to set up a length when you declare arrLines because it is a reference type, which means that it holds an address to the hypothetical array content instead of the array content itself.

System.IO.File.ReadAllLines(strTargetFilePath2); is what creates the array, and yes, that array does have a specific length.

Upvotes: 5

Related Questions