Why isn't this infinite recursion? How does default variable initialization work in VB.NET?

Posted by froadie on Stack Overflow See other posts from Stack Overflow or by froadie
Published on 2010-04-16T15:18:20Z Indexed on 2010/04/18 0:13 UTC
Read the original article Hit count: 155

I just made an interesting mistake in my code:

Dim endColumn As Integer = startColumn + endColumn - 1

The code was actually supposed to be:

Dim endColumn As Integer = startColumn + numColumns - 1

The interesting thing is, I would think that this code should be recursive and loop indefinitely, as the initialization of endColumn sort of calls itself. However, it seems that the code just treats the uninitialized variable as a 0 and so I get startColumn + 0 - 1. What is happening here behind the scenes? When does a variable get assigned a default value?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about initialization