Why infer doesn't work on static but works on dim?

46 Views Asked by At
    Static hashTimeDifferrence As HashSet(Of String) = New HashSet(Of String)

works fine

    Static hashTimeDifferrence = New HashSet(Of String)

doesn't

    Dim hashTimeDifferrence2 = New HashSet(Of String)

works because option infer is on.

I think it should work for dim and static.

Is this a bug in vb.net?

1

There are 1 best solutions below

0
On

There is no fundamental reason why, it is actually just a missed edge case from when Infer was introduced. The former VB PM Anthony Green used it as a reference in how to make breaking changes: https://github.com/dotnet/vblang/issues/312