Why is this infinite recursion? How does default variable initialization work in VB.NET?

I just made an interesting mistake in my code:

Dim endColumn As Integer = startColumn + endColumn - 1

The code was supposed to be:

Dim endColumn As Integer = startColumn + numColumns - 1

Interestingly, I would think that this code should be recursive and the loop is infinite, since initialization of the endColumn type calls the call itself. However, it seems that the code simply treats the uninitialized variable as 0, and so I get startColumn + 0 - 1. What is going on behind the scenes here? When is a variable set to its default value?

+3
source share
3 answers

spec says that:

.

+6

.

1: Dim endColumn As Integer Integer 0, endColumn = 0 .

2: startColumn + endColumn - 1 endColumn = 0 1, , .

+6

. . , , , -, .

-1

Source: https://habr.com/ru/post/1741469/


All Articles