A
Armin Zingler
Hi,
after dealing with the new possiblities of the current VB version, I again
and still wonder why Option Infer can not be used with Option Strict On
at class level, i.e. when declaring a field:
Dim x = 17
Now I found out that the same line does work within a procedure. Actually I
wanted to ask why, but now I see that it is probably because the line is
realy split into declaration and assignment:
private x
sub new
x = 17
end sub
This partially explains the error message, but shouldn't the compiler still
be clever enough to implicitly declare variable x As Integer? It should be
able to infer the type from the expression just like within a procedure.
That's what Option Infer is all about. The compiler does have all the
information. I don't see the problem.
The only explanation I have is that it internally first splits the source
code line into these two parts (declaration+assigment) while loosing the
type information. Avoidable, IMO.
Armin
after dealing with the new possiblities of the current VB version, I again
and still wonder why Option Infer can not be used with Option Strict On
at class level, i.e. when declaring a field:
Dim x = 17
Now I found out that the same line does work within a procedure. Actually I
wanted to ask why, but now I see that it is probably because the line is
realy split into declaration and assignment:
private x
sub new
x = 17
end sub
This partially explains the error message, but shouldn't the compiler still
be clever enough to implicitly declare variable x As Integer? It should be
able to infer the type from the expression just like within a procedure.
That's what Option Infer is all about. The compiler does have all the
information. I don't see the problem.
The only explanation I have is that it internally first splits the source
code line into these two parts (declaration+assigment) while loosing the
type information. Avoidable, IMO.
Armin